public void convertUnitTestNullUnitIds() { double convertedValue = Double.NaN; CswNbtUnitConversion ConversionObj = new CswNbtUnitConversion(TestData.CswNbtResources, null, null); convertedValue = ConversionObj.convertUnit(1); Assert.AreEqual(convertedValue, 1); }
public void convertUnitTestNullUnitOfMeasure() { Double ValueToConvert = 4; CswNbtNode LiterNode = TestData.Nodes.createUnitOfMeasureNode("Volume", "Liters", 1.0, 0, CswEnumTristate.True); CswNbtUnitConversion ConversionObj = new CswNbtUnitConversion(TestData.CswNbtResources, null, LiterNode.NodeId); double Actual = ConversionObj.convertUnit(ValueToConvert); Assert.AreEqual(ValueToConvert, Actual); }
} // DispenseIn() #endregion Public Methods #region Private Methods private double _getDispenseAmountInProperUnits(double Amount, CswPrimaryKey OldUnitId, CswPrimaryKey NewUnitId) { double convertedValue = Amount; if (OldUnitId != NewUnitId) { CswNbtUnitConversion ConversionObj = new CswNbtUnitConversion(_CswNbtResources, OldUnitId, NewUnitId, _Container.Material.RelatedNodeId); convertedValue = ConversionObj.convertUnit(Amount); } return(convertedValue); }
public void convertUnitTestNullQuantity() { Double ValueToConvert = Double.NaN; CswNbtNode LiterNode = TestData.Nodes.createUnitOfMeasureNode("Volume", "Liters", 1.0, 0, CswEnumTristate.True); CswNbtNode MilliliterNode = TestData.Nodes.createUnitOfMeasureNode("Volume", "mL", 1.0, -3, CswEnumTristate.True); Double Expected = 0; CswNbtUnitConversion ConversionObj = new CswNbtUnitConversion(TestData.CswNbtResources, LiterNode.NodeId, MilliliterNode.NodeId); Double Actual = ConversionObj.convertUnit(ValueToConvert); Assert.AreEqual(Expected, Actual); }
public void convertUnitTestWikiExample() { Double ValueToConvert = 3; CswNbtNode OuncesNode = TestData.Nodes.createUnitOfMeasureNode("Weight", "ounces", 2.83495231, -2, CswEnumTristate.True); CswNbtNode MilligramNode = TestData.Nodes.createUnitOfMeasureNode("Weight", "mg", 1.0, -6, CswEnumTristate.True); Double Expected = 85048.56; //Rounding to sixth significant digit since the numbers are stored in the DB as number (15,6) CswNbtUnitConversion ConversionObj = new CswNbtUnitConversion(TestData.CswNbtResources, OuncesNode.NodeId, MilligramNode.NodeId); Double Actual = Math.Round(ConversionObj.convertUnit(ValueToConvert), 6); Assert.AreEqual(Expected, Actual, "Conversion applied incorrectly."); }
public void convertUnitTestSameUnitType() { Double ValueToConvert = 4; CswNbtNode LiterNode = TestData.Nodes.createUnitOfMeasureNode("Volume", "Liters", 1.0, 0, CswEnumTristate.True); CswNbtNode MilliliterNode = TestData.Nodes.createUnitOfMeasureNode("Volume", "mL", 1.0, -3, CswEnumTristate.True); Double Expected = 4000; CswNbtUnitConversion ConversionObj = new CswNbtUnitConversion(TestData.CswNbtResources, LiterNode.NodeId, MilliliterNode.NodeId); Double Actual = ConversionObj.convertUnit(ValueToConvert); Assert.AreEqual(Expected, Actual, "Conversion applied incorrectly."); }
private bool _addToCurrentQuantity(CswNbtObjClassInventoryLevel InventoryLevel, double Quantity, CswPrimaryKey UnitId, string Reason) { bool Ret = false; if (null != InventoryLevel) { CswNbtUnitConversion Conversion = new CswNbtUnitConversion(_CswNbtResources, UnitId, InventoryLevel.Level.UnitId, InventoryLevel.Material.RelatedNodeId); InventoryLevel.CurrentQuantity.Quantity += Conversion.convertUnit(Quantity); InventoryLevel.CurrentQuantityLog.AddComment(Reason); InventoryLevel.postChanges(true); Ret = true; } return(Ret); }
public void convertUnitTestVolumeToWeight() { Double ValueToConvert = 1; CswNbtNode LiterNode = TestData.Nodes.createUnitOfMeasureNode("Volume", "Liters", 1.0, 0, CswEnumTristate.True); CswNbtNode PoundsNode = TestData.Nodes.createUnitOfMeasureNode("Weight", "lb", 4.53592, -1, CswEnumTristate.True); CswNbtNode ChemicalNode = TestData.Nodes.createMaterialNode("Chemical", "Liquid", 1); Double Expected = 2.205; CswNbtUnitConversion ConversionObj = new CswNbtUnitConversion(TestData.CswNbtResources, LiterNode.NodeId, PoundsNode.NodeId, ChemicalNode.NodeId); Double Actual = ConversionObj.convertUnit(ValueToConvert); Assert.AreEqual(Expected, Math.Round(Actual, 3), "Conversion applied incorrectly."); }
public void convertUnitTestWeightToVolumeUnitTypes() { Double ValueToConvert = 4; CswNbtNode GramNode = TestData.Nodes.createUnitOfMeasureNode("Weight", "g", 1.0, -3, CswEnumTristate.True); CswNbtNode LiterNode = TestData.Nodes.createUnitOfMeasureNode("Volume", "Liters", 1.0, 0, CswEnumTristate.True); CswNbtNode ChemicalNode = TestData.Nodes.createMaterialNode("Chemical", "Liquid", .1); Double Expected = 0.04; CswNbtUnitConversion ConversionObj = new CswNbtUnitConversion(TestData.CswNbtResources, GramNode.NodeId, LiterNode.NodeId, ChemicalNode.NodeId); Double Actual = ConversionObj.convertUnit(ValueToConvert); Assert.AreEqual(Expected, Actual, "Conversion applied incorrectly."); }
//updates total dispensed for all dispense request fulfillment actions private void _onCreateFromRequestItem() { if( CswTools.IsPrimaryKey( RequestItem.RelatedNodeId ) ) { CswNbtObjClassRequestItem RequestItemNode = _CswNbtResources.Nodes[RequestItem.RelatedNodeId]; if( null != RequestItemNode ) { if( Type.Value == CswEnumNbtContainerDispenseType.Dispense.ToString() ) { CswNbtUnitConversion Conversion = new CswNbtUnitConversion( _CswNbtResources, QuantityDispensed.UnitId, RequestItemNode.TotalDispensed.UnitId, RequestItemNode.Material.RelatedNodeId ); double DispensedQuantity = Conversion.convertUnit( QuantityDispensed.Quantity ); RequestItemNode.TotalDispensed.Quantity -= DispensedQuantity; // Subtracting a negative number in order to add RequestItemNode.FulfillmentHistory.AddComment( "Dispensed " + QuantityDispensed.Gestalt + " into " + CswNbtNode.getNodeLink( DestinationContainer.RelatedNodeId, DestinationContainer.Gestalt ) ); RequestItemNode.Status.Value = CswNbtObjClassRequestItem.Statuses.Dispensed; } RequestItemNode.postChanges( false ); } } }
public void convertUnitTestLbToKgToLb() { Double ValueToConvert = 1; CswNbtNode LbNode = TestData.Nodes.createUnitOfMeasureNode("Weight", "lb", 4.53592, -1, CswEnumTristate.True);//4.5359237 CswNbtNode KgNode = TestData.Nodes.createUnitOfMeasureNode("Weight", "kg", 1.0, 0, CswEnumTristate.True); Double Expected = 1; CswNbtUnitConversion ConversionObj = new CswNbtUnitConversion(TestData.CswNbtResources, LbNode.NodeId, KgNode.NodeId); Double ValueInKg = ConversionObj.convertUnit(ValueToConvert); Assert.AreEqual(.453592, ValueInKg); CswNbtUnitConversion ConversionObj2 = new CswNbtUnitConversion(TestData.CswNbtResources, KgNode.NodeId, LbNode.NodeId); Double Actual = ConversionObj2.convertUnit(ValueInKg); Assert.AreEqual(Expected, Actual); //For this case, we want everything to just round to the nearest 3 decimal places in the Tier II report, like so: Assert.AreEqual(1, Math.Round(.999999, 3)); Assert.AreEqual(.499, Math.Round(.499, 3)); Assert.AreEqual(.345, Math.Round(.34549, 3)); Assert.AreEqual(.346, Math.Round(.34550, 3)); }
/// <summary> /// Takes the current Quantity value, converts it to the proper kg and Liters values, and stores it in Val_kg and Val_Liters /// </summary> public void SyncConvertedVals(CswPrimaryKey MaterialId = null) { if (null != UnitId) { CswNbtObjClassUnitOfMeasure CurrentUnit = _CswNbtResources.Nodes[UnitId]; if (CurrentUnit.UnitType.Value == CswEnumNbtUnitTypes.Weight.ToString() || CurrentUnit.UnitType.Value == CswEnumNbtUnitTypes.Volume.ToString()) { CswNbtUnitViewBuilder UnitBuilder = new CswNbtUnitViewBuilder(_CswNbtResources); CswNbtObjClassUnitOfMeasure kgUnit = UnitBuilder.getUnit("kg", "Unit_Weight"); CswNbtObjClassUnitOfMeasure LitersUnit = UnitBuilder.getUnit("Liters", "Unit_Volume"); if (null != kgUnit && (CurrentUnit.UnitType.Value == kgUnit.UnitType.Value || MaterialId != null)) { CswNbtUnitConversion Conversion = new CswNbtUnitConversion(_CswNbtResources, UnitId, kgUnit.NodeId, MaterialId); Val_kg = Conversion.convertUnit(Quantity); } if (null != LitersUnit && (CurrentUnit.UnitType.Value == LitersUnit.UnitType.Value || MaterialId != null)) { CswNbtUnitConversion Conversion = new CswNbtUnitConversion(_CswNbtResources, UnitId, LitersUnit.NodeId, MaterialId); Val_Liters = Conversion.convertUnit(Quantity); } } } }
public TierIIData getTierIIData_old(TierIIData.TierIIDataRequest Request) { BaseUnit = _setBaseUnit("kg", "Unit_Weight"); CswNbtObjClassUnitOfMeasure PoundsUnit = _setBaseUnit("lb", "Unit_Weight"); CswNbtUnitConversion Conversion = (BaseUnit != null && PoundsUnit != null) ? new CswNbtUnitConversion(_CswNbtResources, BaseUnit.NodeId, PoundsUnit.NodeId) : new CswNbtUnitConversion(); LocationIds = _setLocationIds(Request.LocationId); DataTable MaterialsTable = _getTierIIMaterials(Request); foreach (DataRow MaterialRow in MaterialsTable.Rows) { CswPrimaryKey BaseUnitId = CswConvert.ToPrimaryKey("nodes_" + MaterialRow["unitid"]); if (null != BaseUnit && BaseUnit.NodeId != BaseUnitId) { //Theoretically, this should never happen //(unless we decide, one day, to change the unit in which we're storing TierII quantity data) BaseUnit = _CswNbtResources.Nodes.GetNode(BaseUnitId); Conversion.setOldUnitProps(BaseUnit); } Double MaxQty = Math.Round(Conversion.convertUnit(CswConvert.ToDouble(MaterialRow["maxqty"])), 3); Double AverageQty = Math.Round(Conversion.convertUnit(CswConvert.ToDouble(MaterialRow["avgqty"])), 3); TierIIData.TierIIMaterial Material = new TierIIData.TierIIMaterial { MaterialId = MaterialRow["materialid"].ToString(), TradeName = MaterialRow["tradename"].ToString(), CASNo = MaterialRow["casno"].ToString(), MaterialType = MaterialRow["materialtype"].ToString(), PhysicalState = MaterialRow["physicalstate"].ToString(), EHS = MaterialRow["specialflags"].ToString().Contains("EHS"), TradeSecret = MaterialRow["specialflags"].ToString().Contains("Trade Secret"), MaxQty = MaxQty, MaxQtyRangeCode = _getRangeCode(MaxQty), AverageQty = AverageQty, AverageQtyRangeCode = _getRangeCode(AverageQty), DaysOnSite = CswConvert.ToInt32(MaterialRow["daysonsite"]), Unit = PoundsUnit != null ? PoundsUnit.Name.Text : "lb" }; CswCommaDelimitedString Hazards = new CswCommaDelimitedString(); Hazards.FromString(MaterialRow["hazardcategories"].ToString()); foreach (String Hazard in Hazards) { Material.HazardCategories.Add(Hazard); } DataTable ContainerStorageCodesTable = _getContainerStorageProps(Material.MaterialId, Request); foreach (DataRow ContainerPropsRow in ContainerStorageCodesTable.Rows) { TierIIData.StorageCodes StorageCodes = new TierIIData.StorageCodes { Pressure = ContainerPropsRow["pressure"].ToString(), Temperature = ContainerPropsRow["temperature"].ToString(), UseType = ContainerPropsRow["usetype"].ToString() }; Material.Storage.Add(StorageCodes); } DataTable ContainerLocationsTable = _getContainerLocations(Material.MaterialId, Request); foreach (DataRow ContainerLocsRow in ContainerLocationsTable.Rows) { TierIIData.StorageLocations Location = new TierIIData.StorageLocations { LocationId = ContainerLocsRow["locationid"].ToString(), Location = ContainerLocsRow["fulllocation"].ToString() }; Material.Locations.Add(Location); } Data.Materials.Add(Material); } return(Data); }
private void _addQuantityDataToHMISMaterial(HMISData.HMISMaterial Material, String UseType, Double Quantity_Kgs, Double Quantity_Lts, string PhysState, CswPrimaryKey MaterialId) { CswNbtUnitConversion Conversion1 = new CswNbtUnitConversion(_CswNbtResources, _getUnitIdByName("kg"), _getBaseUnitId(PhysState), MaterialId); Double ConvertedQty1 = Conversion1.convertUnit(Quantity_Kgs); CswNbtUnitConversion Conversion2 = new CswNbtUnitConversion(_CswNbtResources, _getUnitIdByName("Liters"), _getBaseUnitId(PhysState), MaterialId); Double ConvertedQty2 = Conversion2.convertUnit(Quantity_Lts); Double ConvertedQty = ConvertedQty1 + ConvertedQty2; switch (UseType) { case CswEnumNbtContainerUseTypes.Storage: switch (PhysState.ToLower()) { case CswNbtPropertySetMaterial.CswEnumPhysicalState.Solid: Material.Storage.Solid.Qty += ConvertedQty; break; case CswNbtPropertySetMaterial.CswEnumPhysicalState.Liquid: Material.Storage.Liquid.Qty += ConvertedQty; break; case CswNbtPropertySetMaterial.CswEnumPhysicalState.Gas: Material.Storage.Gas.Qty += ConvertedQty; break; } break; case CswEnumNbtContainerUseTypes.Closed: switch (PhysState.ToLower()) { case CswNbtPropertySetMaterial.CswEnumPhysicalState.Solid: Material.Storage.Solid.Qty += ConvertedQty; Material.Closed.Solid.Qty += ConvertedQty; break; case CswNbtPropertySetMaterial.CswEnumPhysicalState.Liquid: Material.Storage.Liquid.Qty += ConvertedQty; Material.Closed.Liquid.Qty += ConvertedQty; break; case CswNbtPropertySetMaterial.CswEnumPhysicalState.Gas: Material.Storage.Gas.Qty += ConvertedQty; Material.Closed.Gas.Qty += ConvertedQty; break; } break; case CswEnumNbtContainerUseTypes.Open: switch (PhysState.ToLower()) { case CswNbtPropertySetMaterial.CswEnumPhysicalState.Solid: Material.Open.Solid.Qty += ConvertedQty; break; case CswNbtPropertySetMaterial.CswEnumPhysicalState.Liquid: Material.Open.Liquid.Qty += ConvertedQty; break; } break; } } // _addQuantityDataToHMISMaterial()