public override void update() { CswNbtMetaDataFieldType QuantityFT = _CswNbtSchemaModTrnsctn.MetaData.getFieldType(CswEnumNbtFieldType.Quantity); CswTableUpdate QtyUpdate = _CswNbtSchemaModTrnsctn.makeCswTableUpdate("QuantityVal_kgLiters_Update", "jct_nodes_props"); DataTable QtyPropsTable = QtyUpdate.getTable("where nodetypepropid in (select nodetypepropid from nodetype_props where fieldtypeid = " + QuantityFT.FieldTypeId + ") "); foreach (DataRow Row in QtyPropsTable.Rows) { CswPrimaryKey UnitId = new CswPrimaryKey("nodes", CswConvert.ToInt32(Row["field1_fk"].ToString())); CswNbtObjClassUnitOfMeasure CurrentUnit = _CswNbtSchemaModTrnsctn.Nodes[UnitId]; if (null != CurrentUnit && (CurrentUnit.UnitType.Value == CswEnumNbtUnitTypes.Weight.ToString() || CurrentUnit.UnitType.Value == CswEnumNbtUnitTypes.Volume.ToString())) { Double Quantity = CswConvert.ToDouble(Row["field1_numeric"].ToString()); if (CswTools.IsDouble(Quantity)) { CswNbtObjClassUnitOfMeasure kgUnit = getUnit("kg", "Unit_Weight"); CswNbtObjClassUnitOfMeasure LitersUnit = getUnit("Liters", "Unit_Volume"); if (null != kgUnit && CurrentUnit.UnitType.Value == kgUnit.UnitType.Value) { Double Val_kg = Quantity * CurrentUnit.ConversionFactor.RealValue / kgUnit.ConversionFactor.RealValue; Row["field2_numeric"] = Val_kg.ToString(); } if (null != LitersUnit && CurrentUnit.UnitType.Value == LitersUnit.UnitType.Value) { Double Val_Liters = Quantity * CurrentUnit.ConversionFactor.RealValue / LitersUnit.ConversionFactor.RealValue; Row["field3_numeric"] = Val_Liters.ToString(); } } } } QtyUpdate.update(QtyPropsTable); }
/// <summary> /// Determines if a set of values are valid for unit conversion. /// </summary> private void _validateValuesForConversion(Double ValueToConvert, Double OldConversionFactor, Double NewConversionFactor, Double SpecificGravity) { string ErrorMessage = String.Empty; if (false == CswTools.IsDouble(ValueToConvert)) { ErrorMessage = "Value to convert is undefined: " + ValueToConvert; } else if (false == CswTools.IsDouble(OldConversionFactor) || OldConversionFactor <= 0) { ErrorMessage = "Current unit's conversion factor is invalid: " + OldConversionFactor; } else if (false == CswTools.IsDouble(NewConversionFactor) || NewConversionFactor <= 0) { ErrorMessage = "New unit's conversion factor is invalid: " + NewConversionFactor; } else if (false == CswTools.IsDouble(SpecificGravity) || SpecificGravity <= 0) { ErrorMessage = "Material's specific gravity is invalid: " + SpecificGravity; } if (false == String.IsNullOrEmpty(ErrorMessage)) { throw new CswDniException(CswEnumErrorType.Warning, ErrorMessage, "Unit conversion failed."); } }
protected override void beforeWriteNodeLogic(bool Creating, bool OverrideUniqueValidation) { if (CswEnumTristate.False == this.QuantityEditable.Checked && false == CswTools.IsDouble(this.InitialQuantity.Quantity)) { throw new CswDniException(CswEnumErrorType.Warning, "Cannot have a null Initial Quantity if Quantity Editable is unchecked.", "Cannot have a null Initial Quantity if Quantity Editable is unchecked."); } }//beforeWriteNode()
/// <summary> /// WCF method to fulfill a Move Containers request /// </summary> public static void fulfillContainerMoveRequest(ICswResources CswResources, CswNbtRequestDataModel.CswRequestReturn Ret, CswNbtRequestDataModel.RequestFulfill Request) { CswNbtResources NbtResources = _validate(CswResources); CswNbtObjClassRequestItem RequestItem = NbtResources.Nodes[Request.RequestItemId]; if (null != RequestItem) { Int32 ContainersMoved = moveContainers(NbtResources, RequestItem, Request); Ret.Data.Succeeded = ContainersMoved > 0; if (Ret.Data.Succeeded) { if (CswTools.IsDouble(RequestItem.TotalMoved.Value)) { RequestItem.TotalMoved.Value += ContainersMoved; } else { RequestItem.TotalMoved.Value = ContainersMoved; } RequestItem.Status.Value = CswNbtObjClassRequestItem.Statuses.Moved; RequestItem.FulfillmentHistory.AddComment("Moved " + ContainersMoved + " containers to " + CswNbtNode.getNodeLink(RequestItem.Location.SelectedNodeId, RequestItem.Location.CachedFullPath)); RequestItem.postChanges(ForceUpdate: false); } } }
internal CswNbtNode createMaterialNode(string NodeTypeName = "Chemical", string State = "Liquid", double SpecificGravity = 1.0, string PPE = "", string Hazards = "", string SpecialFlags = "", string CASNo = "12-34-0", CswEnumTristate IsTierII = null, Collection <CswNbtNode> Constituents = null, int ConstPercentage = 10) { IsTierII = IsTierII ?? CswEnumTristate.True; CswNbtNode ret = _CswNbtResources.Nodes.makeNodeFromNodeTypeId(_getNodeTypeId(NodeTypeName), delegate(CswNbtNode NewNode) { CswNbtObjClassChemical MaterialNode = NewNode; if (CswTools.IsDouble(SpecificGravity)) { MaterialNode.SpecificGravity.Value = SpecificGravity; } MaterialNode.PhysicalState.Value = State; MaterialNode.TradeName.Text = "Fake Chemical " + Sequence; MaterialNode.PartNumber.Text = "ABC00" + Sequence; if (NodeTypeName == "Chemical") { if (false == String.IsNullOrEmpty(PPE)) { _setMultiListValue(MaterialNode.Node, PPE, "PPE"); } if (false == String.IsNullOrEmpty(Hazards)) { _setMultiListValue(MaterialNode.Node, Hazards, "Hazard Classes"); } MaterialNode.postChanges(true); _setMultiListValue(MaterialNode.Node, SpecialFlags, "Special Flags"); MaterialNode.CasNo.Text = CASNo; MaterialNode.IsTierII.Checked = IsTierII; if (null != Constituents) { foreach (CswNbtNode Constituent in Constituents) { _CswNbtResources.Nodes.makeNodeFromNodeTypeId(_getNodeTypeId("Material Component"), delegate(CswNbtNode Node) { CswNbtObjClassMaterialComponent MaterialComponentNode = Node; MaterialComponentNode.Mixture.RelatedNodeId = MaterialNode.NodeId; MaterialComponentNode.Constituent.RelatedNodeId = Constituent.NodeId; //MaterialComponentNode.LowPercentageValue.Value = ConstPercentage; //MaterialComponentNode.TargetPercentageValue.Value = ConstPercentage; //MaterialComponentNode.HighPercentageValue.Value = ConstPercentage; //MaterialComponentNode.Percentage.Value = ConstPercentage; MaterialComponentNode.PercentageRange.Lower = ConstPercentage; MaterialComponentNode.PercentageRange.Target = ConstPercentage; MaterialComponentNode.PercentageRange.Upper = ConstPercentage; }); } } } }, OverrideUniqueValidation: true); _finalize(); return(ret); }
private void _validateConversionFactor() { if (UnitType.Value != CswEnumNbtUnitTypes.Each.ToString() && false == CswTools.IsDouble(ConversionFactor.RealValue)) { throw new CswDniException ( CswEnumErrorType.Warning, "Units of type " + UnitType.Value + " must have a Conversion Factor.", "Unit of Measure cannot be used for unit conversion." ); } }
private bool _validateDispenseAmmount(ref OperationData OpData) { bool ret = false; if (CswTools.IsDouble(OpData.Field2.Value)) { ret = true; } else { OpData.Field2.StatusMsg = "Error: " + OpData.Field2.Value + " is not a number"; } return(ret); }
/// <summary> /// Takes a numeric value and interconverts it between different Unit Types using the class-set UnitOfMeasure and Material prop values. /// If unit conversion cannot be applied, an error is thrown. /// </summary> public Double convertUnit(Double ValueToConvert) { Double ConvertedValue = ValueToConvert; if (false == CswTools.IsDouble(ConvertedValue)) { ConvertedValue = 0.0; } else if (CswTools.IsDouble(_OldConversionFactor) && CswTools.IsDouble(_NewConversionFactor)) { CswEnumNbtUnitTypeRelationship UnitRelationship = _getUnitTypeRelationship(_OldUnitType, _NewUnitType); if (UnitRelationship == CswEnumNbtUnitTypeRelationship.Same) { ConvertedValue = _applyUnitConversion(ValueToConvert, _OldConversionFactor, _NewConversionFactor); } else if (UnitRelationship != CswEnumNbtUnitTypeRelationship.NotSupported) { if (CswTools.IsDouble(_MaterialSpecificGravity)) { //UnitType-specific logic (Operator logic defined in W1005) if (UnitRelationship == CswEnumNbtUnitTypeRelationship.WeightToVolume) { ConvertedValue = _applyUnitConversion(ValueToConvert, _OldConversionFactor, _NewConversionFactor, 1.0 / _MaterialSpecificGravity); } else if (UnitRelationship == CswEnumNbtUnitTypeRelationship.VolumeToWeight) { ConvertedValue = _applyUnitConversion(ValueToConvert, _OldConversionFactor, _NewConversionFactor, _MaterialSpecificGravity); } } else { _CswNbtResources.logMessage("Conversion failed: The Container Material's specific gravity is undefined."); } } else { _CswNbtResources.logMessage("Conversion failed: Unable to apply unit conversion between the selected unit types."); } } else { _CswNbtResources.logMessage("Conversion failed: Unable to determine appropriate conversion factors."); } return(ConvertedValue); }
} // DispenseOut() /// <summary> /// Dispense into this container. /// </summary> /// <param name="DispenseType"></param> /// <param name="QuantityToAdd">Positive quantity to add</param> /// <param name="UnitId"></param> /// <param name="RequestItemId"></param> /// <param name="SourceContainer"></param> public void DispenseIn(CswEnumNbtContainerDispenseType DispenseType, double QuantityToAdd, CswPrimaryKey UnitId, CswPrimaryKey RequestItemId = null, CswNbtObjClassContainer SourceContainer = null, bool RecordTransaction = true) { double RealQuantityToAdd = _getDispenseAmountInProperUnits(QuantityToAdd, UnitId, _Container.Quantity.UnitId); double CurrentQuantity = 0; if (CswTools.IsDouble(_Container.Quantity.Quantity)) { CurrentQuantity = _Container.Quantity.Quantity; } _Container.Quantity.Quantity = CurrentQuantity + RealQuantityToAdd; if (RecordTransaction) { _ContainerDispenseTransactionBuilder.create(DispenseType, RealQuantityToAdd, _Container.Quantity.UnitId, RequestItemId, SourceContainer, _Container, IsImport: _IsImport); } CswEnumNbtContainerLocationTypeOptions ContainerLocationType = SourceContainer == null ? CswEnumNbtContainerLocationTypeOptions.Receipt : CswEnumNbtContainerLocationTypeOptions.Dispense; _Container.CreateContainerLocationNode(ContainerLocationType); } // DispenseIn()
internal CswNbtNode createUnitOfMeasureNode(string NodeTypeName, string Name, double ConversionFactorBase, int ConversionFactorExponent, CswEnumTristate Fractional) { CswNbtNode ret = _CswNbtResources.Nodes.makeNodeFromNodeTypeId(_getNodeTypeId("Unit_" + NodeTypeName), delegate(CswNbtNode NewNode) { CswNbtObjClassUnitOfMeasure UnitOfMeasureNode = NewNode; UnitOfMeasureNode.Name.Text = Name + "Test"; if (CswTools.IsDouble(ConversionFactorBase)) { UnitOfMeasureNode.ConversionFactor.Base = ConversionFactorBase; } if (ConversionFactorExponent != Int32.MinValue) { UnitOfMeasureNode.ConversionFactor.Exponent = ConversionFactorExponent; } UnitOfMeasureNode.Fractional.Checked = Fractional; UnitOfMeasureNode.UnitType.Value = NodeTypeName; }); _finalize(); return(ret); }
/// <summary> /// Dispense out of this container. /// </summary> /// <param name="DispenseType"></param> /// <param name="QuantityToDeduct">Positive quantity to subtract</param> /// <param name="UnitId"></param> /// <param name="RequestItemId"></param> /// <param name="DestinationContainer"></param> public void DispenseOut(CswEnumNbtContainerDispenseType DispenseType, double QuantityToDeduct, CswPrimaryKey UnitId, CswPrimaryKey RequestItemId = null, CswNbtObjClassContainer DestinationContainer = null, bool RecordTransaction = true) { double RealQuantityToDeduct = _getDispenseAmountInProperUnits(QuantityToDeduct, UnitId, _Container.Quantity.UnitId); double CurrentQuantity = 0; if (CswTools.IsDouble(_Container.Quantity.Quantity)) { CurrentQuantity = _Container.Quantity.Quantity; } _Container.Quantity.Quantity = CurrentQuantity - RealQuantityToDeduct; if (DestinationContainer != null) { DestinationContainer.DispenseIn(DispenseType, QuantityToDeduct, UnitId, RequestItemId, _Container, false); // false, because we do not want another duplicate transaction record } if (RecordTransaction) { _ContainerDispenseTransactionBuilder.create(DispenseType, -RealQuantityToDeduct, _Container.Quantity.UnitId, RequestItemId, _Container, DestinationContainer); } _Container.CreateContainerLocationNode(CswEnumNbtContainerLocationTypeOptions.Dispense); } // DispenseOut()
internal CswNbtNode createConstituentNode(string NodeTypeName = "Chemical", string State = "Liquid", double SpecificGravity = 1.0, string CASNo = "12-34-0", CswEnumTristate IsTierII = null) { IsTierII = IsTierII ?? CswEnumTristate.True; CswNbtNode ret = _CswNbtResources.Nodes.makeNodeFromNodeTypeId(_getNodeTypeId("Constituent"), delegate(CswNbtNode NewNode) { CswNbtObjClassChemical MaterialNode = NewNode; if (CswTools.IsDouble(SpecificGravity)) { MaterialNode.SpecificGravity.Value = SpecificGravity; } MaterialNode.PhysicalState.Value = State; MaterialNode.TradeName.Text = "Fake Constituent " + Sequence; MaterialNode.PartNumber.Text = "ABC00" + Sequence; MaterialNode.CasNo.Text = CASNo; MaterialNode.IsTierII.Checked = IsTierII; }, OverrideUniqueValidation: true); _finalize(); return(ret); }
public JObject getQuantityFromSize(CswPrimaryKey SizeId, string Action) { JObject Ret = new JObject(); CswNbtObjClassSize Size = _CswNbtResources.Nodes.GetNode(SizeId); if (null != Size) { CswNbtNodePropQuantity InitialQuantity = Size.InitialQuantity; InitialQuantity.ToJSON(Ret); Ret["unitName"] = Ret["name"]; Ret["qtyReadonly"] = false; Ret["isUnitReadOnly"] = false; Ret["unitCount"] = "1"; Ret["isRequired"] = InitialQuantity.Required.ToString(); if (Action.ToLower() == ChemSW.Nbt.ObjClasses.CswEnumNbtButtonAction.receive.ToString()) { Ret["isUnitReadOnly"] = true; if (Size.QuantityEditable.Checked == CswEnumTristate.False) { Ret["qtyReadonly"] = true; } Ret["unitCount"] = CswTools.IsDouble(Size.UnitCount.Value) ? Size.UnitCount.Value.ToString() : ""; } else if (Action.ToLower() == ChemSW.Nbt.ObjClasses.CswEnumNbtButtonAction.dispense.ToString()) { CswNbtObjClassUnitOfMeasure UnitNode = _CswNbtResources.Nodes.GetNode(Size.InitialQuantity.UnitId); if (null != UnitNode && (UnitNode.UnitType.Value == CswEnumNbtUnitTypes.Each.ToString() || false == CswTools.IsDouble(UnitNode.ConversionFactor.Base))) { Ret["isUnitReadOnly"] = true; } } } return(Ret); }