public double GetWeightObsolete(WeightUnit weightUnit)
        {
            const double WEIGHT_IN_POUNDS = 11.11;
            const double WEIGHT_IN_OUNCES = 177.76;

            return(weightUnit == WeightUnit.POUND ? WEIGHT_IN_POUNDS : WEIGHT_IN_OUNCES);
        }
Beispiel #2
0
        public string ToString(WeightUnit unit)
        {
            var valuesKg = List(FuelToDest, FuelCont, FuelHold, FuelExtra, FuelToAltn,
                                FuelFinalRsv, TakeoffFuel, FuelApu, FuelTaxi, TotalFuel);

            var names = List("TRIP", "CONTINGENCY", "HOLD", "EXTRA", "ALTERNATE",
                             "FINAL RSV", "AT T/O", "APU", "TAXI", "TOTAL");

            var times = List(TimeToDest, TimeCont, TimeHold, TimeExtra, TimeToAltn,
                             TimeFinalRsv, TimeTakeoff, TimeApu, TimeTaxi, TimeTotal);

            var linebreakCount = List(1, 1, 1, 1, 1, 2, 2, 1, 2, 1);

            var ratio   = unit == WeightUnit.KG ? 1.0 : KgLbRatio;
            var value   = valuesKg.Select(x => (x * ratio).ToString("F0"));
            var timeStr = times.Select(t => MinToHHMM(RoundToInt(t)));
            var lines   = names
                          .Zip(value, (n, v) => LineFormat(n, v))
                          .Zip(timeStr, (s, t) => s + "  " + t);
            var linebreaks = linebreakCount.Select(c => new string('\n', c));
            var combined   = lines.Zip(linebreaks, (s, b) => s + b);
            var joined     = string.Concat(combined);

            var wt = "ALL WEIGHTS IN " + WeightUnitToString(unit);

            return(wt + "\n\n" + new string(' ', RightPad + LeftPad - 4) +
                   "FUEL  TIME\n" + joined + LineFormat("FMC RSV", FormatFmcRsv(FuelFmcRsv * ratio)));
        }
 /// <summary>
 /// For all Package items in this list their weight is converted to the given weight unit
 /// and their dimensions are converted to the given measurement unit.
 /// </summary>
 /// <param name="toW">The weight unit to convert to</param>
 /// <param name="toM">The measurement unit to convert to</param>
 public void ConvertBoth(WeightUnit toW, MeasurementUnit toM)
 {
     foreach (Package item in this)
     {
         item.ConvertBoth(toW, toM);
     }
 }
        public void DeserializeCustomUnitAsPredefined_ShouldReturnValidResult()
        {
            // arrange
            var someUnit = new WeightUnit(
                name: "some unit",
                abbreviation: "su",
                valueInKilograms: (number)123.456m);
            string json      = @"{
  'unit': 'su'
}";
            var    converter = new WeightUnitJsonConverter(
                serializationFormat: LinearUnitJsonSerializationFormat.PredefinedAsString,
                tryReadCustomPredefinedUnit: (string value, out WeightUnit predefinedUnit) =>
            {
                if (value == someUnit.Abbreviation)
                {
                    predefinedUnit = someUnit;
                    return(true);
                }

                predefinedUnit = default(WeightUnit);
                return(false);
            });

            // act
            var result = JsonConvert.DeserializeObject <SomeUnitOwner <WeightUnit> >(json, converter);

            // assert
            result.Unit.Should().Be(someUnit);
        }
 public AircraftConfigItem(
     string AC,
     string Registration,
     string FuelProfile,
     string TOProfile,
     string LdgProfile,
     double OewKg,
     double MaxTOWtKg,
     double MaxLdgWtKg,
     double MaxZfwKg,
     double MaxFuelKg,
     double FuelBias,
     WeightUnit WtUnit)
 {
     this.AC           = AC;
     this.Registration = Registration;
     this.FuelProfile  = FuelProfile;
     this.TOProfile    = TOProfile;
     this.LdgProfile   = LdgProfile;
     this.OewKg        = OewKg;
     this.MaxTOWtKg    = MaxTOWtKg;
     this.MaxLdgWtKg   = MaxLdgWtKg;
     this.WtUnit       = WtUnit;
     this.MaxZfwKg     = MaxZfwKg;
     this.MaxFuelKg    = MaxFuelKg;
     this.FuelBias     = FuelBias;
 }
 public void Put(string id, WeightUnit entity)
 {
     if (ModelState.IsValid)
     {
         db.UpdateWeightUnit(entity.GetPrivateEntity <WeightUnit>());
     }
 }
 /// <summary>
 /// For all Package items in this list their weight is converted to the given weight unit.
 /// </summary>
 /// <param name="to">The weight unit to convert to</param>
 public void ConvertWeight(WeightUnit to)
 {
     foreach (Package item in this)
     {
         item.ConvertWeight(to);
     }
 }
Beispiel #8
0
            private static IEnumerable <TryParsWeightUnitTestData> GetParsableUnitsTestData()
            {
                foreach (var predefinedUnit in WeightUnit.GetPredefinedUnits())
                {
                    yield return(new TryParsWeightUnitTestData(predefinedUnit, predefinedUnit.Name));

                    yield return(new TryParsWeightUnitTestData(predefinedUnit, predefinedUnit.Abbreviation));
                }
            }
Beispiel #9
0
            public void ShouldConvertToExpectedValue(Weight originalWeight, WeightUnit targetUnit, Weight expectedWeight)
            {
                // arrange
                // act
                var actualWeight = originalWeight.Convert(targetUnit);

                // assert
                actualWeight.Should().Be(expectedWeight);
                actualWeight.Unit.Should().Be(targetUnit);
            }
            private static IEnumerable <ExactlyParsableUnitTestData> GetExactlyParsableUnitsTestData()
            {
                foreach (var unit in WeightUnit.GetPredefinedUnits())
                {
                    yield return(new ExactlyParsableUnitTestData(unit.Name, "l", unit));

                    yield return(new ExactlyParsableUnitTestData(unit.Abbreviation, "s", unit));

                    yield return(new ExactlyParsableUnitTestData(unit.Name + "s", "ll", unit));
                }
            }
Beispiel #11
0
 public WeightTextBoxController(
     TextBox txtBox,
     Label lable     = null,
     string format   = "F0",           // Display as integer
     WeightUnit unit = WeightUnit.KG)
 {
     this.TxtBox = txtBox;
     this.Lable  = lable;
     this.format = format;
     this._unit  = unit;
 }
 protected void ToString(List <string> toStringOutput)
 {
     toStringOutput.Add($"CustomUnit = {(CustomUnit == null ? "null" : CustomUnit.ToString())}");
     toStringOutput.Add($"AreaUnit = {(AreaUnit == null ? "null" : AreaUnit.ToString())}");
     toStringOutput.Add($"LengthUnit = {(LengthUnit == null ? "null" : LengthUnit.ToString())}");
     toStringOutput.Add($"VolumeUnit = {(VolumeUnit == null ? "null" : VolumeUnit.ToString())}");
     toStringOutput.Add($"WeightUnit = {(WeightUnit == null ? "null" : WeightUnit.ToString())}");
     toStringOutput.Add($"GenericUnit = {(GenericUnit == null ? "null" : GenericUnit.ToString())}");
     toStringOutput.Add($"TimeUnit = {(TimeUnit == null ? "null" : TimeUnit.ToString())}");
     toStringOutput.Add($"Type = {(Type == null ? "null" : Type.ToString())}");
 }
Beispiel #13
0
        public static string ToDisplayString(this WeightUnit @this)
        {
            switch (@this)
            {
            case WeightUnit.Kilogram:
                return("kg");

            default:
                return("lb");
            }
        }
Beispiel #14
0
 public UnitSystem(
     string id,
     WeightUnit baseWeightUnit,
     LengthUnit baseLengthUnit,
     PowerUnit basePowerUnit)
 {
     ID             = Assert.IsNotNullOrWhiteSpace(id, nameof(id));
     BaseWeightUnit = baseWeightUnit;
     BaseLengthUnit = baseLengthUnit;
     BasePowerUnit  = basePowerUnit;
 }
Beispiel #15
0
 /// <summary>
 ///     创建包裹对象
 /// </summary>
 /// <param name="length">包裹长度</param>
 /// <param name="width">包裹宽度</param>
 /// <param name="height">包裹高度</param>
 /// <param name="weight">包裹重量</param>
 /// <param name="insuredValue">保险费用</param>
 /// <param name="weiUnit">重量单位</param>
 /// <param name="linearUnit">长度单位</param>
 /// <param name="currency">货币</param>
 public Package(decimal length, decimal width, decimal height, decimal weight, decimal insuredValue, WeightUnit weiUnit = WeightUnit.KG, LinearUnit linearUnit = LinearUnit.CM, string currency = "CNY")
 {
     Length         = length;
     Width          = width;
     Height         = height;
     Weight         = weight;
     InsuredValue   = insuredValue;
     ShipWeightUnit = weiUnit;
     ShipLinearUnit = linearUnit;
     Currency       = currency;
 }
            public void ParamlessConstructedWeightUnit_ShouldBeEqualToKilogram()
            {
                // arrange
                var paramlessConstructedWeightUnit = new WeightUnit();
                var kilogram = WeightUnit.Kilogram;

                // act
                // assert
                kilogram.Equals(paramlessConstructedWeightUnit).Should().BeTrue(because: "'WeightUnit.Kilogram' should be equal 'new WeightUnit()'");
                paramlessConstructedWeightUnit.Equals(kilogram).Should().BeTrue(because: "'new WeightUnit()' should be equal 'WeightUnit.Kilogram'");
            }
        public string Post(WeightUnit entity)
        {
            if (ModelState.IsValid)
            {
                db.InsertWeightUnit(entity);

                entity.PublicId = entity.GetPublicId();
                return(entity.GetPublicEntity <WeightUnit>().PublicId);
            }

            return(string.Empty);
        }
Beispiel #18
0
        /// <summary>
        /// Converts the given weight unit into the google equivalent
        /// </summary>
        /// <param name="storeUnit">the store weight unit</param>
        /// <returns>The google specific weight unit for the store</returns>
        /// <remarks>Google supports the same weight units as AC but uses
        /// a different identifier.</remarks>
        private static string GetGoogleWeightUnit(WeightUnit storeUnit)
        {
            switch (storeUnit)
            {
            case WeightUnit.Grams: return("g");

            case WeightUnit.Kilograms: return("kg");

            case WeightUnit.Ounces: return("oz");

            default: return("lb");
            }
        }
        public decimal ConvertWeight(WeightUnit source, WeightUnit destination, decimal input)
        {
            if (source == destination)
            {
                return(input);
            }
            //convert to the lowest unit
            var inputAsGrams = input;

            switch (source)
            {
            case WeightUnit.Gram:
                inputAsGrams = input;
                break;

            case WeightUnit.Kilogram:
                inputAsGrams = input * 1000;
                break;

            case WeightUnit.Ounce:
                inputAsGrams = input * 28.349m;
                break;

            case WeightUnit.Pound:
                inputAsGrams = input * 453.592m;
                break;

            case WeightUnit.Ton:
                inputAsGrams = input * 1000000;
                break;
            }
            switch (destination)
            {
            case WeightUnit.Gram:
                return(inputAsGrams);

            case WeightUnit.Kilogram:
                return(inputAsGrams / 1000);

            case WeightUnit.Ounce:
                return(inputAsGrams / 28.349m);

            case WeightUnit.Pound:
                return(inputAsGrams / 453.592m);

            case WeightUnit.Ton:
                return(inputAsGrams / 1000000);
            }

            return(input);
        }
Beispiel #20
0
        private PackageList PreparePackages(Warehouse origin, Address destination, BasketItemCollection contents)
        {
            PackageList plist = PackageManager.GetPackageList(contents);

            if (plist == null || plist.Count == 0)
            {
                return(null);
            }

            ProviderUnits pUnits = GetProviderUnits(origin.Country);
            //GET UNITS USED BY STORE
            Store           store = Token.Instance.Store;
            MeasurementUnit storeMeasurementUnit = store.MeasurementUnit;
            WeightUnit      storeWeightUnit      = store.WeightUnit;

            bool requireMC = storeMeasurementUnit != pUnits.MeasurementUnit;
            bool requireWC = storeWeightUnit != pUnits.WeightUnit;

            if (requireMC && requireWC)
            {
                plist.ConvertBoth(pUnits.WeightUnit, pUnits.MeasurementUnit);
            }
            else if (requireWC)
            {
                plist.ConvertWeight(pUnits.WeightUnit);
            }
            else if (requireMC)
            {
                plist.ConvertDimensions(pUnits.MeasurementUnit);
            }

            WeightUnit sourceUnit = (Token.Instance.Store.WeightUnit == WeightUnit.Grams || Token.Instance.Store.WeightUnit == WeightUnit.Kilograms) ? WeightUnit.Kilograms : WeightUnit.Pounds;
            LSDecimal  maxWeight  = LocaleHelper.ConvertWeight(sourceUnit, MaxPackageWeight, pUnits.WeightUnit);
            LSDecimal  minWeight  = LocaleHelper.ConvertWeight(sourceUnit, MinPackageWeight, pUnits.WeightUnit);

            if (EnablePackageBreakup && maxWeight > 0)
            {
                //compose packages (splits items larger than the maximum carrier weight)
                plist.Compose(maxWeight, minWeight);
            }
            else
            {
                plist.EnsureMinimumWeight(minWeight);
            }

            //convert weight and dimensions to whole numbers
            plist.ConvertDimsToWholeNumbers();
            plist.RoundWeight(1);

            return(plist);
        }
Beispiel #21
0
        /// <summary>
        /// Converts the input weight in specified input units to the output unit type
        /// </summary>
        /// <param name="weight">The measurement</param>
        /// <param name="inputUnit">The unit type of the inputted weight</param>
        /// <param name="outputUnit">The desired output weight once converted</param>
        /// <returns>The converted weight</returns>
        public static decimal ConvertWeight(decimal inputWeight, WeightUnit inputUnit, WeightUnit outputUnit)
        {
            decimal baseNumber = 0;

            switch (inputUnit)
            {
            case WeightUnit.Gram: baseNumber = inputWeight; break;

            case WeightUnit.KiloGram: baseNumber = inputWeight * 1000; break;

            case WeightUnit.Grain: baseNumber = inputWeight * 0.064798903M; break;

            case WeightUnit.Ounce: baseNumber = inputWeight * 28.349523125M; break;

            case WeightUnit.OunceTroy: baseNumber = inputWeight * 31.1034768M; break;

            case WeightUnit.Pound: baseNumber = inputWeight * 453.59237M; break;

            case WeightUnit.Carat: baseNumber = inputWeight * 0.2M; break;

            case WeightUnit.Dram: baseNumber = inputWeight * 0.5643833911933M; break;

            case WeightUnit.Stone: baseNumber = inputWeight * 6350.29318M; break;

            case WeightUnit.Pennyweight: baseNumber = inputWeight * 1.55517384M; break;
            }
            switch (outputUnit)
            {
            case WeightUnit.Gram: return(baseNumber);

            case WeightUnit.KiloGram: return(baseNumber / 1000);

            case WeightUnit.Grain: return(baseNumber / 0.064798903M);

            case WeightUnit.Ounce: return(baseNumber / 28.349523125M);

            case WeightUnit.OunceTroy: return(baseNumber / 31.1034768M);

            case WeightUnit.Pound: return(baseNumber / 453.59237M);

            case WeightUnit.Carat: return(baseNumber / 0.2M);

            case WeightUnit.Dram: return(baseNumber / 0.5643833911933M);

            case WeightUnit.Stone: return(baseNumber / 6350.29318M);

            case WeightUnit.Pennyweight: return(baseNumber / 1.55517384M);
            }
            return(0);
        }
Beispiel #22
0
        public static string LabelIn(WeightUnit unit)
        {
            switch (unit)
            {
            case WeightUnit.Kilogram:
                return("kgs");

            case WeightUnit.Pound:
                return("lbs");

            default:
                throw new ArgumentOutOfRangeException("unit");
            }
        }
Beispiel #23
0
        public double WeightIn(WeightUnit unit)
        {
            switch (unit)
            {
            case WeightUnit.Kilogram:
                return(Kilograms);

            case WeightUnit.Pound:
                return(Pounds);

            default:
                throw new ArgumentOutOfRangeException("unit");
            }
        }
        public void DeserializePredefinedUnitString_ShouldReturnValidResult(WeightUnit expectedUnit)
        {
            // arrange
            string json      = $@"{{
  'unit': '{expectedUnit.Abbreviation}'
}}";
            var    converter = new WeightUnitJsonConverter();

            // act
            var result = JsonConvert.DeserializeObject <SomeUnitOwner <WeightUnit> >(json, converter);

            // assert
            result.Unit.Should().Be(expectedUnit);
        }
Beispiel #25
0
        private WeightUnits GetWeightUnits(WeightUnit wu)
        {
            switch (wu)
            {
            case WeightUnit.Kilograms:
                return(WeightUnits.KG);

            case WeightUnit.Pounds:
                return(WeightUnits.LB);

            default:
                return(WeightUnits.LB);
            }
        }
Beispiel #26
0
        private PackageList PreparePackages(Warehouse origin, BasketItemCollection contents)
        {
            PackageList plist = PackageManager.GetPackageList(contents);

            if (plist == null || plist.Count == 0)
            {
                return(null);
            }

            //GET UNITS USED BY STORE
            Store           store = StoreDataSource.Load(Token.Instance.StoreId);
            MeasurementUnit storeMeasurementUnit = store.MeasurementUnit;
            WeightUnit      storeWeightUnit      = store.WeightUnit;

            bool requireMC = storeMeasurementUnit != MeasurementUnit.Inches;
            bool requireWC = storeWeightUnit != WeightUnit.Ounces;

            if (requireMC && requireWC)
            {
                plist.ConvertBoth(WeightUnit.Ounces, MeasurementUnit.Inches);
            }
            else if (requireWC)
            {
                plist.ConvertWeight(WeightUnit.Ounces);
            }
            else if (requireMC)
            {
                plist.ConvertDimensions(MeasurementUnit.Inches);
            }

            LSDecimal maxWeight = LocaleHelper.ConvertWeight(WeightUnit.Pounds, MaxPackageWeight, WeightUnit.Ounces);
            LSDecimal minWeight = LocaleHelper.ConvertWeight(WeightUnit.Pounds, MinPackageWeight, WeightUnit.Ounces);

            if (EnablePackageBreakup && maxWeight > 0)
            {
                //compose packages (splits items larger than the maximum carrier weight)
                plist.Compose(maxWeight, minWeight);
            }
            else
            {
                plist.EnsureMinimumWeight(minWeight);
            }

            //convert weight to whole number
            //plist.ConvertWeightToWholeNumber();
            //plist.ConvertDimsToWholeNumbers();

            return(plist);
        }
Beispiel #27
0
 public AircraftRequest(
     string Aircraft,
     string Registration,
     double TakeOffWeightKg,
     double LandingWeightKg,
     double ZfwKg,
     WeightUnit WtUnit)
 {
     this.Aircraft        = Aircraft;
     this.Registration    = Registration;
     this.TakeOffWeightKg = TakeOffWeightKg;
     this.LandingWeightKg = LandingWeightKg;
     this.ZfwKg           = ZfwKg;
     this.WtUnit          = WtUnit;
 }
Beispiel #28
0
        public ActionResult WeightSettings(WeightUnit weightUnitsValue)
        {
            var         id          = this.GetUserId();
            UserProfile userprofile = db.UserProfiles.Find(id);

            if (new[] { 0, 1 }.Contains((int)weightUnitsValue))
            {
                userprofile.WeightUnits     = weightUnitsValue;
                db.Entry(userprofile).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", "Dashboard"));
            }

            return(View(userprofile));
        }
        private void RegistrationChanged(object sender, EventArgs e)
        {
            if (registrationComboBox.SelectedIndex < 0)
            {
                return;
            }

            var config = aircrafts.Find(registrationComboBox.Text).Config;

            WeightUnit = config.WtUnit;
            WeightControl.AircraftConfig = config;
            var maxPayloadKg = config.MaxZfwKg - config.OewKg;

            WeightControl.ZfwKg = config.OewKg + 0.5 * maxPayloadKg;
        }
            public void StringFormat_StandardFormat_ShouldReturnProperValue(string unitName, string unitAbbreviation, string standardFormat, string expectedResult, string reason)
            {
                // arrange
                var formatter = new WeightUnitFormatter();
                var weight    = new WeightUnit(
                    name: unitName,
                    abbreviation: unitAbbreviation,
                    valueInKilograms: Fixture.CreatePositiveNumber());

                // act
                string actualResult = formatter.Format(standardFormat, weight);

                // assert
                actualResult.Should().Be(expectedResult, because: reason);
            }
 public static double ReturnKilograms(WeightUnit unit, double number)
 {
     switch (unit)
     {
         case WeightUnit.Ton:
             return number*KiloPerTon;
         case WeightUnit.Kilogram:
             return number;
         case WeightUnit.Gram:
             return number*KiloPerGram;
         case WeightUnit.Pound:
             return number*KiloPerPound;
         default:
             throw new ArgumentOutOfRangeException(nameof(unit), unit, null);
     }
 }
        public WeightAmount ConvertTo(WeightUnit unit)
        {
            if (unit == Unit)
            {
                return this;
            }

            var ratio = 1m;
            switch (Unit)
            {
                case WeightUnit.Kilogram:
                    switch (unit)
                    {
                        case WeightUnit.Pounds:
                            // kg => lb
                            ratio = 2.20462262m;
                            break;
                    }
                    break;

                case WeightUnit.Pounds:
                    switch (unit)
                    {
                        case WeightUnit.Kilogram:
                            // lb => kg
                            ratio = 0.45359237m;
                            break;
                    }
                    break;
            }

            return new WeightAmount
            {
                Special = Special,
                Unit = unit,
                Value = Math.Round(Value * ratio, 2)
            };
        }
Beispiel #33
0
 public static float ConvertWeight(float value, WeightUnit from, WeightUnit to)
 {
     return value * WeightRates[from] / WeightRates[to];
 }
Beispiel #34
0
 // (*) IWeighingUnit
 public void SetUnit(WeightUnit unit)
 {
 }
Beispiel #35
0
 public WeightUnits(double digitField, WeightUnit unit = WeightUnit.Kilogram)
     : base(digitField)
 {
     DigitField = WeightConvertor.ReturnKilograms(unit, digitField);
     NameField = "Kilogram";
 }
 public ResistanceSet(decimal weight, WeightUnit unit, int repetitions)
 {
     this.Weight = weight;
     this.Unit = unit;
     this.Repetitions = repetitions;
 }