Ejemplo n.º 1
0
        public override int GetRoundToDecimalsValue()
        {
            VolumeUnits toUnit = (VolumeUnits)ToUnit;

            switch (toUnit)
            {
            case VolumeUnits.CubicMillimeter:
            case VolumeUnits.Milliliter:
            case VolumeUnits.ImperialFluidOunce:
                return(5);

            case VolumeUnits.CubicMeter:
            case VolumeUnits.CubicCentimeter:
                return(3);

            case VolumeUnits.CubicKilometer:
            case VolumeUnits.USGallon:
            case VolumeUnits.ImperialGallon:
            case VolumeUnits.ImperialFluidQuart:
            case VolumeUnits.ImperialFluidPint:
            case VolumeUnits.Liter:
                return(2);
            }

            throw new Exception("The 'TO' unit enum was improperly defined.");
        }
Ejemplo n.º 2
0
        public VolumeConversions(VolumeUnits from, VolumeUnits to)
        {
            this.FromUnit = from;
            this.ToUnit   = to;

            ConversionFactors = GetConversionFactors();
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public string ToDelimitedString()
        {
            CultureInfo culture = CultureInfo.CurrentCulture;

            return(string.Format(
                       culture,
                       StringHelper.StringFormatSequence(0, 50, Configuration.FieldSeparator),
                       Id,
                       ExternalAccessionIdentifier?.ToDelimitedString(),
                       AccessionIdentifier?.ToDelimitedString(),
                       ContainerIdentifier?.ToDelimitedString(),
                       PrimaryParentContainerIdentifier?.ToDelimitedString(),
                       EquipmentContainerIdentifier?.ToDelimitedString(),
                       SpecimenSource,
                       RegistrationDateTime.HasValue ? RegistrationDateTime.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null,
                       ContainerStatus?.ToDelimitedString(),
                       CarrierType?.ToDelimitedString(),
                       CarrierIdentifier?.ToDelimitedString(),
                       PositionInCarrier?.ToDelimitedString(),
                       TrayTypeSac?.ToDelimitedString(),
                       TrayIdentifier?.ToDelimitedString(),
                       PositionInTray?.ToDelimitedString(),
                       Location != null ? string.Join(Configuration.FieldRepeatSeparator, Location.Select(x => x.ToDelimitedString())) : null,
                       ContainerHeight.HasValue ? ContainerHeight.Value.ToString(Consts.NumericFormat, culture) : null,
                       ContainerDiameter.HasValue ? ContainerDiameter.Value.ToString(Consts.NumericFormat, culture) : null,
                       BarrierDelta.HasValue ? BarrierDelta.Value.ToString(Consts.NumericFormat, culture) : null,
                       BottomDelta.HasValue ? BottomDelta.Value.ToString(Consts.NumericFormat, culture) : null,
                       ContainerHeightDiameterDeltaUnits?.ToDelimitedString(),
                       ContainerVolume.HasValue ? ContainerVolume.Value.ToString(Consts.NumericFormat, culture) : null,
                       AvailableSpecimenVolume.HasValue ? AvailableSpecimenVolume.Value.ToString(Consts.NumericFormat, culture) : null,
                       InitialSpecimenVolume.HasValue ? InitialSpecimenVolume.Value.ToString(Consts.NumericFormat, culture) : null,
                       VolumeUnits?.ToDelimitedString(),
                       SeparatorType?.ToDelimitedString(),
                       CapType?.ToDelimitedString(),
                       Additive != null ? string.Join(Configuration.FieldRepeatSeparator, Additive.Select(x => x.ToDelimitedString())) : null,
                       SpecimenComponent?.ToDelimitedString(),
                       DilutionFactor?.ToDelimitedString(),
                       Treatment?.ToDelimitedString(),
                       Temperature?.ToDelimitedString(),
                       HemolysisIndex.HasValue ? HemolysisIndex.Value.ToString(Consts.NumericFormat, culture) : null,
                       HemolysisIndexUnits?.ToDelimitedString(),
                       LipemiaIndex.HasValue ? LipemiaIndex.Value.ToString(Consts.NumericFormat, culture) : null,
                       LipemiaIndexUnits?.ToDelimitedString(),
                       IcterusIndex.HasValue ? IcterusIndex.Value.ToString(Consts.NumericFormat, culture) : null,
                       IcterusIndexUnits?.ToDelimitedString(),
                       FibrinIndex.HasValue ? FibrinIndex.Value.ToString(Consts.NumericFormat, culture) : null,
                       FibrinIndexUnits?.ToDelimitedString(),
                       SystemInducedContaminants != null ? string.Join(Configuration.FieldRepeatSeparator, SystemInducedContaminants.Select(x => x.ToDelimitedString())) : null,
                       DrugInterference != null ? string.Join(Configuration.FieldRepeatSeparator, DrugInterference.Select(x => x.ToDelimitedString())) : null,
                       ArtificialBlood?.ToDelimitedString(),
                       SpecialHandlingCode != null ? string.Join(Configuration.FieldRepeatSeparator, SpecialHandlingCode.Select(x => x.ToDelimitedString())) : null,
                       OtherEnvironmentalFactors != null ? string.Join(Configuration.FieldRepeatSeparator, OtherEnvironmentalFactors.Select(x => x.ToDelimitedString())) : null,
                       ContainerLength?.ToDelimitedString(),
                       ContainerWidth?.ToDelimitedString(),
                       ContainerForm?.ToDelimitedString(),
                       ContainerMaterial?.ToDelimitedString(),
                       ContainerCommonName?.ToDelimitedString()
                       ).TrimEnd(Configuration.FieldSeparator.ToCharArray()));
        }
Ejemplo n.º 4
0
        public string GetValueInUnits(VolumeUnits units, int decimalPlaces)
        {
            switch (units)
            {
            case VolumeUnits.Liters:
                return(InLiters.ToString($"F{decimalPlaces}"));

            case VolumeUnits.UsGallons:
                return(InUsGallons.ToString($"F{decimalPlaces}"));
            }
            throw new ArgumentException("Unable to return value in" + units.ToString());
        }
Ejemplo n.º 5
0
        public static string GetUnitSymbol(VolumeUnits units)
        {
            switch (units)
            {
            case VolumeUnits.Liters:
                return("L");

            case VolumeUnits.UsGallons:
                return("gal");
            }
            throw new ArgumentException("Unable to return symbol fir" + units.ToString());
        }
Ejemplo n.º 6
0
        public double GetValueInUnits(VolumeUnits units)
        {
            switch (units)
            {
            case VolumeUnits.Liters:
                return(InLiters);

            case VolumeUnits.UsGallons:
                return(InUsGallons);
            }
            throw new ArgumentException("Unable to return value in" + units.ToString());
        }
Ejemplo n.º 7
0
        public static VolumeUnitSimpleType GetVolumeUnit(VolumeUnits units)
        {
            switch (units)
            {
            case VolumeUnits.cubicmeters:
                return(VolumeUnitSimpleType.cubicmeters);

            case VolumeUnits.cubicmillimeters:
                return(VolumeUnitSimpleType.cubicmillimeters);

            case VolumeUnits.cubiccentimeters:
                return(VolumeUnitSimpleType.cubiccentimeters);

            default:
                throw new ArgumentException("Unexpected unit");
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Converts from 1 distance to another. By default, converts to Meter and then back to the other measurements
        /// </summary>
        /// <param name="value">The value of the from unit</param>
        /// <param name="from">From unit can be anything listed in DistanceUnits</param>
        /// <param name="to">To unit can be anything listed in DistanceUnits</param>
        /// <returns></returns>
        public override decimal Convert(decimal value, Enum from, Enum to)
        {
            VolumeUnits fromDu = (VolumeUnits)from;
            VolumeUnits toDu   = (VolumeUnits)to;

            decimal conversion;

            if (!conversionMap.TryGetValue(fromDu, out conversion))
            {
                throw new InvalidUnitTypeException(fromDu.ToString());
            }
            // Convert from to Meter
            value /= conversion;

            // Convert meter to to.
            if (!conversionMap.TryGetValue(toDu, out conversion))
            {
                throw new InvalidUnitTypeException(toDu.ToString());
            }

            return(value * conversion);
        }
Ejemplo n.º 9
0
        /// <inheritdoc/>
        public string ToDelimitedString()
        {
            CultureInfo culture = CultureInfo.CurrentCulture;

            return(string.Format(
                       culture,
                       StringHelper.StringFormatSequence(0, 13, Configuration.FieldSeparator),
                       Id,
                       SetIdBui.HasValue ? SetIdBui.Value.ToString(culture) : null,
                       BloodUnitIdentifier?.ToDelimitedString(),
                       BloodUnitType?.ToDelimitedString(),
                       BloodUnitWeight.HasValue ? BloodUnitWeight.Value.ToString(Consts.NumericFormat, culture) : null,
                       WeightUnits?.ToDelimitedString(),
                       BloodUnitVolume.HasValue ? BloodUnitVolume.Value.ToString(Consts.NumericFormat, culture) : null,
                       VolumeUnits?.ToDelimitedString(),
                       ContainerCatalogNumber,
                       ContainerLotNumber,
                       ContainerManufacturer?.ToDelimitedString(),
                       TransportTemperature?.ToDelimitedString(),
                       TransportTemperatureUnits?.ToDelimitedString()
                       ).TrimEnd(Configuration.FieldSeparator.ToCharArray()));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Unit Weight conversion function from Metric to Metric, Metric to English, or vice versa.
        /// </summary>
        /// <param name="toConvert">Original, operating, unit weight.</param>
        /// <param name="toConvertTo">Measurement unit to convert into (ie cc).</param>
        /// <returns>A new unit weight with correct type and numeric value.</returns>
        public static BaseVolumeScalar ConvertToUnits(BaseVolumeScalar toConvert, VolumeUnits toConvertTo)
        {
            if (toConvert.UnitOfMeasure == toConvertTo)
            {
                return(toConvert);
            }

            double newVal = toConvert.NumericValue;

            if (toConvert.UnitOfMeasure == VolumeUnits.CubicCentimeters && toConvertTo == VolumeUnits.CubicMeters)
            {
                newVal /= 1e6;
            }
            else if (toConvert.UnitOfMeasure == VolumeUnits.CubicCentimeters && toConvertTo == VolumeUnits.CubicFeet)
            {
                newVal /= 28316.8199;
            }
            else if (toConvert.UnitOfMeasure == VolumeUnits.CubicFeet && toConvertTo == VolumeUnits.CubicCentimeters)
            {
                newVal *= 28316.8199;
            }
            else if (toConvert.UnitOfMeasure == VolumeUnits.CubicFeet && toConvertTo == VolumeUnits.CubicMeters)
            {
                newVal /= 35.3147;
            }
            else if (toConvert.UnitOfMeasure == VolumeUnits.CubicMeters && toConvertTo == VolumeUnits.CubicCentimeters)
            {
                newVal *= 1e6;
            }
            else if (toConvert.UnitOfMeasure == VolumeUnits.CubicMeters && toConvertTo == VolumeUnits.CubicFeet)
            {
                newVal *= 35.3147;
            }

            BaseVolumeScalar toReturn = new BaseVolumeScalar(toConvert.Symbol, newVal, toConvertTo);

            return(toReturn);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VolumeOfVoids"/> class.
 /// </summary>
 /// <param name="numericalValue">Decimal value used for calculations.</param>
 /// <param name="units">Measurement units (ie cc).</param>
 public VolumeOfVoids(double numericalValue, VolumeUnits units)
     : base("V_v", numericalValue, units)
 {
 }
Ejemplo n.º 12
0
        public static Task MakeUnitTask(int varMin, int varMax)
        {
            Random r = new Random(Guid.NewGuid().GetHashCode());

            string        unit1 = "";
            string        unit2 = "";
            double        val;
            string        answer   = "";
            Units         unit     = (Units)r.Next(0, 3);
            DistanceUnits distance = (DistanceUnits)r.Next(0, 3);
            WeightUnits   weight   = (WeightUnits)r.Next(0, 2);
            VolumeUnits   volume   = (VolumeUnits)r.Next(0, 2);

            switch (unit)
            {
            case Units.Distance:
                switch (distance)
                {
                case DistanceUnits.Metre:
                    unit1 = "metres";
                    break;

                case DistanceUnits.Centimetre:
                    unit1 = "centimetres";
                    break;

                case DistanceUnits.Millimetre:
                    unit1 = "millimetres";
                    break;
                }
                distance = (DistanceUnits)r.Next(0, 3);

                switch (unit1)
                {
                case "metres":
                    while (unit2 == unit1 || unit2 == "")
                    {
                        switch (distance)
                        {
                        case DistanceUnits.Centimetre:
                            unit2 = "centimetres";
                            break;

                        case DistanceUnits.Millimetre:
                            unit2 = "millimetres";
                            break;

                        case DistanceUnits.Metre:
                            distance = (DistanceUnits)r.Next(0, 3);
                            break;
                        }
                    }
                    break;

                case "centimetres":
                    while (unit2 == unit1 || unit2 == "")
                    {
                        switch (distance)
                        {
                        case DistanceUnits.Metre:
                            unit2 = "metres";
                            break;

                        case DistanceUnits.Millimetre:
                            unit2 = "millimetres";
                            break;

                        case DistanceUnits.Centimetre:
                            distance = (DistanceUnits)r.Next(0, 3);
                            break;
                        }
                    }
                    break;

                case "millimetres":
                    while (unit2 == unit1 || unit2 == "")
                    {
                        switch (distance)
                        {
                        case DistanceUnits.Metre:
                            unit2 = "metres";
                            break;

                        case DistanceUnits.Centimetre:
                            unit2 = "centimetres";
                            break;

                        case DistanceUnits.Millimetre:
                            distance = (DistanceUnits)r.Next(0, 3);
                            break;
                        }
                    }
                    break;
                }
                break;

            case Units.Weight:
                switch (weight)
                {
                case WeightUnits.Kilogram:
                    unit1 = "kilograms";
                    break;

                case WeightUnits.gram:
                    unit1 = "grams";
                    break;
                }
                switch (unit1)
                {
                case "kilograms":
                    unit2 = "gram";
                    break;

                case "grams":
                    unit2 = "kilogram";
                    break;
                }
                break;

            case Units.Volume:
                switch (volume)
                {
                case VolumeUnits.Cubicmetre:
                    unit1 = "cubicmetres";
                    break;

                case VolumeUnits.Litre:
                    unit1 = "litres";
                    break;
                }
                switch (unit1)
                {
                case "cubicmetres":
                    unit2 = "litres";
                    break;

                case "litres":
                    unit2 = "cubicmetres";
                    break;
                }
                break;
            }

            val = r.Next(varMin, varMax);
            string taskS = "";

            taskS += "How many " + unit1 + " is " + val + " " + unit2 + "?";

            //conversions
            if (unit1 == "metres" && unit2 == "centimetres")
            {
                val = val * 0.01;
            }
            else if (unit1 == "metres" && unit2 == "millimetres")
            {
                val = val * 0.001;
            }
            else if (unit1 == "centimetres" && unit2 == "metres")
            {
                val = val * 100;
            }
            else if (unit1 == "centimetres" && unit2 == "millimetres")
            {
                val = val * 0.1;
            }
            else if (unit1 == "millimetres" && unit2 == "metres")
            {
                val = val * 1000;
            }
            else if (unit1 == "millimetres" && unit2 == "centimetres")
            {
                val = val * 10;
            }
            else if (unit1 == "litres")
            {
                val = val * 1000;
            }
            else if (unit1 == "cubicmetres")
            {
                val = val * 0.001;
            }
            else if (unit1 == "gram")
            {
                val = val * 1000;
            }
            else if (unit1 == "kilogram")
            {
                val = val * 0.001;
            }

            answer = val.ToString();

            var task = new Task(taskS, answer);

            return(task);
        }
Ejemplo n.º 13
0
        public void LoadDVH(Structure structure, PlanSetup plan, DoseValuePresentation dosePresentation, VolumePresentation volPresentation, bool useRapPlanEstim = false)
        {
            BinSize = Convert.ToDouble(Myconfig.GetAppKey("DVHBinSize"));
            DVHData      apiDVH    = null;
            EstimatedDVH upEstDVH  = null;
            EstimatedDVH lowEstDVH = null;

            if (volPresentation == VolumePresentation.AbsoluteCm3)
            {
                VolumeUnit = MyDVHData.VolumeUnits.cc;
            }
            else if (volPresentation == VolumePresentation.Relative)
            {
                VolumeUnit = MyDVHData.VolumeUnits.Percent;
            }
            else
            {
                VolumeUnit = MyDVHData.VolumeUnits.Unknown;
            }

            if (useRapPlanEstim)
            {
                upEstDVH  = plan.DVHEstimates.FirstOrDefault(s => s.Structure.Id == structure.Id && s.Type == DVHEstimateType.Upper);
                lowEstDVH = plan.DVHEstimates.FirstOrDefault(s => s.Structure.Id == structure.Id && s.Type == DVHEstimateType.Lower);

                if (upEstDVH == null || lowEstDVH == null)
                {
                    CurveData = null;
                    return;
                }

                //TODO calc these from estimated DVH
                MaxDose  = 0;
                MeanDose = 0;

                DoseUnit  = (MyDVHData.DoseUnits)lowEstDVH.CurveData[0].DoseValue.Unit;
                CurveData = new DVHPoint[lowEstDVH.CurveData.Count()];
                for (int i = 0; i < lowEstDVH.CurveData.Count(); i++)
                {
                    double dose   = lowEstDVH.CurveData[i].DoseValue.Dose;
                    double volume = 0.5 * (lowEstDVH.CurveData[i].Volume + upEstDVH.CurveData[i].Volume);
                    CurveData[i] = new DVHPoint
                    {
                        Dose   = dose,
                        Volume = volume
                    };
                }
            }
            else
            {
                apiDVH = plan.GetDVHCumulativeData(structure, dosePresentation, volPresentation, BinSize);



                if (apiDVH == null)
                {
                    MessageBox.Show("Plan " + plan.Id + " contains no dose\nCannot calculate metrics", "Invalid data", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
                MaxDose  = apiDVH.MaxDose.Dose;
                MeanDose = apiDVH.MeanDose.Dose;

                DoseUnit  = (MyDVHData.DoseUnits)apiDVH.CurveData[0].DoseValue.Unit;
                CurveData = new DVHPoint[apiDVH.CurveData.Count()];
                for (int i = 0; i < apiDVH.CurveData.Count(); i++)
                {
                    CurveData[i] = new DVHPoint
                    {
                        Dose   = apiDVH.CurveData[i].DoseValue.Dose,
                        Volume = apiDVH.CurveData[i].Volume
                    };
                }
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WaterVolume"/> class.
 /// </summary>
 /// <param name="voidVolume">V_v in V_v=V_w+V_g.</param>
 /// <param name="gasVolume">V_g in V_v=V_w+V_g.</param>
 /// <param name="units">Measurement units to hold value after initial calculation (ie cc).</param>
 public WaterVolume(VolumeOfVoids voidVolume, GasVolume gasVolume, VolumeUnits units)
     : this(ConvertToUnits(voidVolume, units).NumericValue - ConvertToUnits(gasVolume, units).NumericValue, units)
 {
 }
Ejemplo n.º 15
0
 public Volume(VolumeUnits currentUnit = VolumeUnits.m3) : base(currentUnit)
 {
     DefaultUnit = VolumeUnits.m3;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TotalVolume"/> class.
 /// </summary>
 /// <param name="porosity">n in n=V_v/V.</param>
 /// <param name="voidVolume">V_v in n=V_v/V.</param>
 /// <param name="units">Measurement system to hold value after initial calculation (ie cc).</param>
 public TotalVolume(Porosity porosity, VolumeOfVoids voidVolume, VolumeUnits units)
     : this(BaseVolumeScalar.ConvertToUnits(voidVolume, units).NumericValue / porosity.NumericValue, units)
 {
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TotalVolume"/> class.
 /// </summary>
 /// <param name="numericalValue">Decimal value to do calculations with.</param>
 /// <param name="units">Measurement system (ie cc).</param>
 public TotalVolume(double numericalValue, VolumeUnits units)
     : base("V", numericalValue, units)
 {
 }
Ejemplo n.º 18
0
        //Method for laoding units into combo boxes
        private void UnitsLoading(string SelectedOp)
        {
            try
            {
                if (units == null)
                {
                }
                else
                {
                    units.Clear();
                    if (unitsMults == null)
                    {
                    }
                    else
                    {
                        unitsMults.Clear();
                    }
                }
                units      = new List <string>();
                unitsMults = new List <string>();

                switch (SelectedOp)
                {
                case "Length":
                {
                    LengthUnits unit      = new LengthUnits();
                    MetersMults mults     = new MetersMults();
                    var         units2    = Enum.GetValues(unit.GetType());
                    var         multiples = Enum.GetValues(mults.GetType());
                    foreach (var item in units2)
                    {
                        units.Add(item.ToString());
                    }
                    foreach (var item in multiples)
                    {
                        unitsMults.Add(item.ToString());
                    }
                    break;
                }

                case "Mass and Weight":
                {
                    MassUnits  unit      = new MassUnits();
                    KilogMults mults     = new KilogMults();
                    var        multiples = Enum.GetValues(mults.GetType());
                    var        units2    = Enum.GetValues(unit.GetType());
                    foreach (var item in units2)
                    {
                        units.Add(item.ToString());
                    }
                    foreach (var item in multiples)
                    {
                        unitsMults.Add(item.ToString());
                    }
                    break;
                }

                case "Power":
                {
                    PowerUnits unit      = new PowerUnits();
                    WattMults  mults     = new WattMults();
                    var        multiples = Enum.GetValues(mults.GetType());
                    var        units2    = Enum.GetValues(unit.GetType());
                    foreach (var item in units2)
                    {
                        units.Add(item.ToString());
                    }
                    foreach (var item in multiples)
                    {
                        unitsMults.Add(item.ToString());
                    }
                    break;
                }

                case "Pressure":
                {
                    PressureUnits unit      = new PressureUnits();
                    PascaMults    mults     = new PascaMults();
                    var           multiples = Enum.GetValues(mults.GetType());
                    var           units2    = Enum.GetValues(unit.GetType());
                    foreach (var item in units2)
                    {
                        units.Add(item.ToString());
                    }
                    foreach (var item in multiples)
                    {
                        unitsMults.Add(item.ToString());
                    }
                    break;
                }

                case "Energy":
                {
                    EnergyUnits unit      = new EnergyUnits();
                    JouleMults  mults     = new JouleMults();
                    var         multiples = Enum.GetValues(mults.GetType());
                    var         units2    = Enum.GetValues(unit.GetType());
                    foreach (var item in units2)
                    {
                        units.Add(item.ToString());
                    }
                    foreach (var item in multiples)
                    {
                        unitsMults.Add(item.ToString());
                    }
                    break;
                }

                case "Temperature":
                {
                    TemperatureUnits unit = new TemperatureUnits();
                    var units2            = Enum.GetValues(unit.GetType());

                    foreach (var item in units2)
                    {
                        units.Add(item.ToString());
                    }
                    unitsMults.Add("Temperature doesn't have Multiples\n Please choose other option");
                    break;
                }

                case "Volume":
                {
                    VolumeUnits unit      = new VolumeUnits();
                    M3Mults     mults     = new M3Mults();
                    var         multiples = Enum.GetValues(mults.GetType());
                    var         units2    = Enum.GetValues(unit.GetType());
                    foreach (var item in units2)
                    {
                        units.Add(item.ToString());
                    }
                    foreach (var item in multiples)
                    {
                        unitsMults.Add(item.ToString());
                    }
                    break;
                }

                case "Angle":
                {
                    AngleUnits unit   = new AngleUnits();
                    var        units2 = Enum.GetValues(unit.GetType());
                    foreach (var item in units2)
                    {
                        units.Add(item.ToString());
                    }
                    unitsMults.Add("Angle doesn't have Multiples\n Please choose other option");
                    break;
                }

                case "Area":
                {
                    AreaUnits     unit      = new AreaUnits();
                    MetersqrMults mults     = new MetersqrMults();
                    var           multiples = Enum.GetValues(mults.GetType());
                    var           units2    = Enum.GetValues(unit.GetType());
                    foreach (var item in units2)
                    {
                        units.Add(item.ToString());
                    }
                    foreach (var item in multiples)
                    {
                        unitsMults.Add(item.ToString());
                    }
                    break;
                }

                case "Speed":
                {
                    SpeedUnits unit      = new SpeedUnits();
                    MPSMults   mults     = new MPSMults();
                    var        multiples = Enum.GetValues(mults.GetType());
                    var        units2    = Enum.GetValues(unit.GetType());
                    foreach (var item in units2)
                    {
                        units.Add(item.ToString());
                    }
                    foreach (var item in multiples)
                    {
                        unitsMults.Add(item.ToString());
                    }
                    break;
                }

                case "Time":
                {
                    TimeUnits unit   = new TimeUnits();
                    var       units2 = Enum.GetValues(unit.GetType());
                    foreach (var item in units2)
                    {
                        units.Add(item.ToString());
                    }
                    unitsMults.Add("Time doesn't have Multiples\n Please choose other option");
                    break;
                }
                }

                Fromcombo.Items.Clear();
                ToCombo.Items.Clear();
                MultsFromcombo.Items.Clear();
                MultsTocombo.Items.Clear();


                foreach (var v in units)
                {
                    ComboBoxItem boxItem = new ComboBoxItem();
                    boxItem.Background      = new SolidColorBrush(Color.FromArgb(System.Convert.ToByte(255), System.Convert.ToByte(40), System.Convert.ToByte(40), System.Convert.ToByte(40)));
                    boxItem.Foreground      = Brushes.Beige;
                    boxItem.Opacity         = 0.8;
                    boxItem.BorderThickness = new Thickness(0.0);
                    boxItem.Content         = v;
                    Fromcombo.Items.Add(boxItem);
                }

                foreach (var v in units)
                {
                    ComboBoxItem boxItem = new ComboBoxItem();
                    boxItem.Background      = new SolidColorBrush(Color.FromArgb(System.Convert.ToByte(255), System.Convert.ToByte(40), System.Convert.ToByte(40), System.Convert.ToByte(40)));
                    boxItem.Foreground      = Brushes.Beige;
                    boxItem.Opacity         = 0.8;
                    boxItem.BorderThickness = new Thickness(0.0);
                    boxItem.Content         = v;
                    ToCombo.Items.Add(boxItem);
                }

                foreach (var v in unitsMults)
                {
                    ComboBoxItem boxItem = new ComboBoxItem();
                    boxItem.Background      = new SolidColorBrush(Color.FromArgb(System.Convert.ToByte(255), System.Convert.ToByte(40), System.Convert.ToByte(40), System.Convert.ToByte(40)));
                    boxItem.Foreground      = Brushes.Beige;
                    boxItem.Opacity         = 0.8;
                    boxItem.BorderThickness = new Thickness(0.0);
                    boxItem.Content         = v;
                    MultsFromcombo.Items.Add(boxItem);
                }

                foreach (var v in unitsMults)
                {
                    ComboBoxItem boxItem = new ComboBoxItem();
                    boxItem.Background      = new SolidColorBrush(Color.FromArgb(System.Convert.ToByte(255), System.Convert.ToByte(40), System.Convert.ToByte(40), System.Convert.ToByte(40)));
                    boxItem.Foreground      = Brushes.Beige;
                    boxItem.Opacity         = 0.8;
                    boxItem.BorderThickness = new Thickness(0.0);
                    boxItem.Content         = v;
                    MultsTocombo.Items.Add(boxItem);
                }


                Fromcombo.SelectedIndex      = 0;
                ToCombo.SelectedIndex        = 0;
                MultsFromcombo.SelectedIndex = 0;
                MultsTocombo.SelectedIndex   = 0;
                SelectedFrom = Fromcombo.SelectedItem.ToString().Remove(0, 38);
                SelectedTo   = ToCombo.SelectedItem.ToString().Remove(0, 38);
                SelMultsFrom = MultsFromcombo.SelectedItem.ToString().Remove(0, 38);
                SelMultsTo   = MultsTocombo.SelectedItem.ToString().Remove(0, 38);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message + "\nPlease Retry", "Loading-Content-Error");
            }
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseVolumeScalar"/> class.
 /// </summary>
 /// <param name="symbol">LateX symbol for pretty print.</param>
 /// <param name="numericalValue">Decimal value for calculation.</param>
 /// <param name="units">Measurement unit (ie cc).</param>
 public BaseVolumeScalar(string symbol, double numericalValue, VolumeUnits units)
 {
     this.UnitOfMeasure = units;
     this.Symbol        = symbol;
     this.NumericValue  = numericalValue;
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VolumeOfVoids"/> class.
 /// </summary>
 /// <param name="waterVolume">V_w in V_v=V_w+V_g.</param>
 /// <param name="gasVolume">V_g in V_v=V_w+V_g.</param>
 /// <param name="units">Measurement units to hold value after initial calculation (ie cc).</param>
 public VolumeOfVoids(WaterVolume waterVolume, GasVolume gasVolume, VolumeUnits units)
     : this(ConvertToUnits(waterVolume, units).NumericValue + ConvertToUnits(gasVolume, units).NumericValue, units)
 {
 }
Ejemplo n.º 21
0
        static int makeUnitTask(int varMin, int varMax)
        {
            //1-Distance
            double metre      = 1;
            double centimetre = metre * 0.01;
            double millimetre = metre * 0.001;
            //2-weight
            double kilogram = 1;
            double gram     = kilogram * 0.01;
            //3-volume
            double cubicMetre = 1;
            double litre      = cubicMetre * 0.001;



            Random r = new Random(Guid.NewGuid().GetHashCode());

            string        unit1 = "";
            string        unit2 = "";
            int           val;
            Units         unit     = (Units)r.Next(0, 2);
            DistanceUnits distance = (DistanceUnits)r.Next(0, 2);
            WeightUnits   weight   = (WeightUnits)r.Next(0, 1);
            VolumeUnits   volume   = (VolumeUnits)r.Next(0, 1);

            switch (unit)
            {
            case Units.Distance:
                switch (distance)
                {
                case DistanceUnits.Metre:
                    unit1 = "metre";
                    break;

                case DistanceUnits.Centimetre:
                    unit1 = "centimetre";
                    break;

                case DistanceUnits.Millimetre:
                    unit1 = "millimetre";
                    break;
                }
                distance = (DistanceUnits)r.Next(0, 3);

                switch (unit1)
                {
                case "metre":
                    while (unit2 == unit1 || unit2 == "")
                    {
                        switch (distance)
                        {
                        case DistanceUnits.Centimetre:
                            unit2 = "centimetre";
                            break;

                        case DistanceUnits.Millimetre:
                            unit2 = "millimetre";
                            break;

                        case DistanceUnits.Metre:
                            unit2 = "metre";
                            break;
                        }
                    }
                    break;

                case "centimetre":
                    while (unit2 == unit1 || unit2 == "")
                    {
                        switch (distance)
                        {
                        case DistanceUnits.Metre:
                            unit2 = "metre";
                            break;

                        case DistanceUnits.Millimetre:
                            unit2 = "millimetre";
                            break;

                        case DistanceUnits.Centimetre:
                            unit2 = "millimetre";
                            break;
                        }
                    }
                    break;

                case "millimetre":
                    switch (distance)
                    {
                    case DistanceUnits.Metre:
                        unit2 = "metre";
                        break;

                    case DistanceUnits.Centimetre:
                        unit2 = "centimetre";
                        break;

                    case DistanceUnits.Millimetre:
                        unit2 = "millimetre";
                        break;
                    }
                    break;
                }
                break;

            case Units.Weight:
                switch (weight)
                {
                case WeightUnits.Kilogram:
                    unit1 = "kilogram";
                    break;

                case WeightUnits.gram:
                    unit1 = "gram";
                    break;
                }
                switch (unit1)
                {
                case "kilogram":
                    unit2 = "gram";
                    break;

                case "gram":
                    unit2 = "kilogram";
                    break;
                }
                break;

            case Units.Volume:
                switch (volume)
                {
                case VolumeUnits.Cubicmetre:
                    unit1 = "cubicmetre";
                    break;

                case VolumeUnits.Litre:
                    unit1 = "litre";
                    break;
                }
                switch (unit1)
                {
                case "cubicmetre":
                    unit2 = "litre";
                    break;

                case "litre":
                    unit2 = "cubicmetre";
                    break;
                }
                break;
            }

            val = r.Next(varMin, varMax);

            Console.WriteLine("how many {0}(s) is {1} {2}(s)", unit1, val, unit2);

            var mytask = new Task("funfunfunfunfun", "bretty gud");

            Console.WriteLine(mytask.Solution);
            Console.WriteLine(mytask.TaskDescription);

            return(0);
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VolumeOfVoids"/> class.
 /// </summary>
 /// <param name="solidVolume">V_s in V=V_s+V_v.</param>
 /// <param name="totalVolume">V in V=V_s+V_v.</param>
 /// <param name="units">Measurement units to hold value after initial calculation (ie cc).</param>
 public VolumeOfVoids(VolumeOfSolidMatter solidVolume, TotalVolume totalVolume, VolumeUnits units)
     : this(ConvertToUnits(totalVolume, units).NumericValue - ConvertToUnits(solidVolume, units).NumericValue, units)
 {
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TotalVolume"/> class.
 /// </summary>
 /// <param name="solidVolume">V_s in V = V_s+V_v.</param>
 /// <param name="voidVolume">V_v in V = V_s+V_v.</param>
 /// <param name="units">Measurement system to hold value after initial calculation (ie cc).</param>
 public TotalVolume(VolumeOfSolidMatter solidVolume, VolumeOfVoids voidVolume, VolumeUnits units)
     : this(ConvertToUnits(solidVolume, units).NumericValue + ConvertToUnits(voidVolume, units).NumericValue, units)
 {
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VolumeOfVoids"/> class.
 /// </summary>
 /// <param name="porosity">n in n=V_v/V.</param>
 /// <param name="totalVolume">V in n=V_v/V.</param>
 /// <param name="units">Measurement units to hold value after initial calculation (ie cc).</param>
 public VolumeOfVoids(Porosity porosity, TotalVolume totalVolume, VolumeUnits units)
     : this(BaseVolumeScalar.ConvertToUnits(totalVolume, units).NumericValue *porosity.NumericValue, units)
 {
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GasVolume"/> class.
 /// </summary>
 /// <param name="numericalValue">Decimal value used for calculations.</param>
 /// <param name="units">Measurement unit (ie cc).</param>
 public GasVolume(double numericalValue, VolumeUnits units)
     : base("V_g", numericalValue, units)
 {
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VolumeOfVoids"/> class.
 /// </summary>
 /// <param name="voidRatio">e in e=V_v/V_s.</param>
 /// <param name="solidVolume">V_s in e=V_v/V_s.</param>
 /// <param name="units">Measurement units to hold value after initial calculation (ie cc).</param>
 public VolumeOfVoids(VoidRatio voidRatio, VolumeOfSolidMatter solidVolume, VolumeUnits units)
     : this(BaseVolumeScalar.ConvertToUnits(solidVolume, units).NumericValue *voidRatio.NumericValue, units)
 {
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WaterVolume"/> class.
 /// </summary>
 /// <param name="numericalValue">Decimal value used for calculations.</param>
 /// <param name="units">Measurement units (ie cc).</param>
 public WaterVolume(double numericalValue, VolumeUnits units)
     : base("V_w", numericalValue, units)
 {
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VolumeOfVoids"/> class.
 /// </summary>
 /// <param name="degreeOfSaturation">S in S=V_w/V_v.</param>
 /// <param name="waterVolume">V_w in S=V_w/V_v.</param>
 /// <param name="units">Measurement units to hold value after initial calculation (ie cc).</param>
 public VolumeOfVoids(DegreeOfSaturation degreeOfSaturation, WaterVolume waterVolume, VolumeUnits units)
     : this(BaseVolumeScalar.ConvertToUnits(waterVolume, units).NumericValue / degreeOfSaturation.NumericValue, units)
 {
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WaterVolume"/> class.
 /// </summary>
 /// <param name="degreeOfSaturation">S in S=V_w/V_v.</param>
 /// <param name="voidVolume">V_v in S=V_w/V_v.</param>
 /// <param name="units">Measurement units to hold value after initial calculation (ie cc).</param>
 public WaterVolume(DegreeOfSaturation degreeOfSaturation, VolumeOfVoids voidVolume, VolumeUnits units)
     : this(ConvertToUnits(voidVolume, units).NumericValue *degreeOfSaturation.NumericValue, units)
 {
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VolumeOfSolidMatter"/> class.
 /// </summary>
 /// <param name="numericalValue">Decimal value used for calculations.</param>
 /// <param name="units">Measurement units (ie cc).</param>
 public VolumeOfSolidMatter(double numericalValue, VolumeUnits units)
     : base("V_s", numericalValue, units)
 {
 }