Beispiel #1
0
 public override void ReadJSON(JObject JObject, Dictionary <Int32, Int32> NodeMap, Dictionary <Int32, Int32> NodeTypeMap)
 {
     if (null != JObject[_ValueSubField.ToXmlNodeName(true)])
     {
         Value = CswConvert.ToDouble(JObject[_ValueSubField.ToXmlNodeName(true)]);
     }
 }
Beispiel #2
0
        public override void CommitOperation(ref OperationData OpData)
        {
            CswNbtObjClassContainer containerToDispense = _CswNbtResources.Nodes[OpData.Field1.NodeId];

            if (_CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Edit, containerToDispense.NodeType) && _CswNbtResources.Permit.can(CswEnumNbtActionName.DispenseContainer))
            {
                double quantityToDispense = CswConvert.ToDouble(OpData.Field2.Value);
                if (quantityToDispense > containerToDispense.Quantity.Quantity)
                {
                    OpData.Field2.StatusMsg = "Cannot dispense " + quantityToDispense + containerToDispense.Quantity.CachedUnitName + " when containter only has " + containerToDispense.Quantity.Gestalt;
                    OpData.Log.Add(DateTime.Now + " - ERROR: Attempted to dispense " + quantityToDispense + containerToDispense.Quantity.CachedUnitName + " when containter only has " + containerToDispense.Quantity.Gestalt);
                    OpData.Field2.ServerValidated = false;
                }
                else
                {
                    containerToDispense.DispenseOut(CswEnumNbtContainerDispenseType.Dispense, quantityToDispense, containerToDispense.Quantity.UnitId);
                    containerToDispense.postChanges(false);
                    OpData.Field1.SecondValue = " (current quantity: " + containerToDispense.Quantity.Quantity + containerToDispense.Quantity.CachedUnitName + ")";
                    OpData.Log.Add(DateTime.Now + " - Dispensed " + OpData.Field2.Value + " " + containerToDispense.Quantity.CachedUnitName + " out of container " + containerToDispense.Barcode.Barcode + ". " + containerToDispense.Quantity.Gestalt + " left in container");
                    base.CommitOperation(ref OpData);
                }
            }
            else
            {
                string statusMsg = "You do not have permission to dispense Container (" + OpData.Field2.Value + ")";
                OpData.Field2.StatusMsg       = statusMsg;
                OpData.Field2.ServerValidated = false;
                OpData.Log.Add(DateTime.Now + " - ERROR: " + statusMsg);
            }
        }
        public JObject dispenseSourceContainer(string DispenseType, string Quantity, string UnitId, string RequestItemId)
        {
            JObject ret = new JObject();

            if (null != _SourceContainer)
            {
                CswEnumNbtContainerDispenseType DispenseTypeEnum = _getDispenseTypeFromAction(DispenseType);
                CswPrimaryKey UnitOfMeasurePk = new CswPrimaryKey();
                UnitOfMeasurePk.FromString(UnitId);
                CswPrimaryKey RequestItemPk = new CswPrimaryKey();
                RequestItemPk.FromString(RequestItemId);
                Double RealQuantity = CswConvert.ToDouble(Quantity);

                if (DispenseTypeEnum == CswEnumNbtContainerDispenseType.Add)
                {
                    RealQuantity = -RealQuantity; // deducting negative quantity is adding quantity
                }

                _SourceContainer.DispenseOut(DispenseTypeEnum, RealQuantity, UnitOfMeasurePk, RequestItemPk);
                _SourceContainer.postChanges(false);

                string ViewId = _getViewForAllDispenseContainers();
                ret["viewId"] = ViewId;
            }
            return(ret);
        }
        public JObject dispenseIntoChildContainers(string ContainerNodeTypeId, string DispenseGrid, string RequestItemId)
        {
            JObject ret = new JObject();

            if (null != _SourceContainer)
            {
                CswPrimaryKey RequestItemPk = new CswPrimaryKey();
                RequestItemPk.FromString(RequestItemId);
                JArray  GridArray = JArray.Parse(DispenseGrid);
                JObject jBarcodes = new JObject();
                ret["barcodes"] = jBarcodes;
                for (Int32 i = 0; i < GridArray.Count; i += 1)
                {
                    if (GridArray[i].Type == JTokenType.Object)
                    {
                        JObject CurrentRow               = (JObject)GridArray[i];
                        int     NumOfContainers          = CswConvert.ToInt32(CurrentRow["containerNo"]);
                        double  QuantityToDispense       = CswConvert.ToDouble(CurrentRow["quantity"]);
                        string  UnitId                   = CswConvert.ToString(CurrentRow["unitid"]);
                        CswCommaDelimitedString Barcodes = new CswCommaDelimitedString();
                        Barcodes.FromString(CswConvert.ToString(CurrentRow["barcodes"]));

                        CswPrimaryKey UnitOfMeasurePK = new CswPrimaryKey();
                        UnitOfMeasurePK.FromString(UnitId);

                        if (NumOfContainers == 0)
                        {
                            _SourceContainer.DispenseOut(
                                CswEnumNbtContainerDispenseType.Dispense, QuantityToDispense,
                                UnitOfMeasurePK, RequestItemPk);
                            _SourceContainer.postChanges(false);
                        }
                        else
                        {
                            for (Int32 c = 0; c < NumOfContainers; c += 1)
                            {
                                CswNbtObjClassContainer ChildContainer = _createChildContainer(ContainerNodeTypeId,
                                                                                               UnitOfMeasurePK, Barcodes[c]);
                                _SourceContainer.DispenseOut(
                                    CswEnumNbtContainerDispenseType.Dispense, QuantityToDispense,
                                    UnitOfMeasurePK, RequestItemPk, ChildContainer);
                                //ChildContainer.DispenseIn( CswEnumNbtContainerDispenseType.Dispense, QuantityToDispense, UnitOfMeasurePK, RequestItemPk, _SourceContainer );
                                ChildContainer.postChanges(false);

                                JObject BarcodeNode = new JObject();
                                jBarcodes[ChildContainer.NodeId.ToString()] = BarcodeNode;
                                BarcodeNode["nodeid"]   = ChildContainer.NodeId.ToString();
                                BarcodeNode["nodename"] = ChildContainer.NodeName;
                            }
                            _SourceContainer.postChanges(false);
                        }
                    }
                }
                _SourceContainer.postChanges(false);

                string ViewId = _getViewForAllDispenseContainers();
                ret["viewId"] = ViewId;
            }
            return(ret);
        }
        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);
        }
 public override void ReadDataRow(DataRow PropRow, Dictionary <string, Int32> NodeMap, Dictionary <Int32, Int32> NodeTypeMap)
 {
     if (PropRow.Table.Columns.Contains(_BaseSubField.ToXmlNodeName(true)))
     {
         Base = CswConvert.ToDouble(PropRow[_BaseSubField.ToXmlNodeName(true)].ToString());
     }
     if (PropRow.Table.Columns.Contains(_ExponentSubField.ToXmlNodeName(true)))
     {
         Base = CswConvert.ToInt32(PropRow[_ExponentSubField.ToXmlNodeName(true)].ToString());
     }
 }
        private Double _getRowDoubleVal(CswEnumNbtPropColumn ColumnName)
        {
            Double ReturnVal = Double.NaN;

            if (_PropRow != null)
            {
                if (_PropsTable.Columns.Contains(ColumnName.ToString()) && !_PropRow.IsNull(ColumnName.ToString()))
                {
                    ReturnVal = CswConvert.ToDouble(_PropRow[ColumnName.ToString()]);
                }
            }
            return(ReturnVal);
        }
        public static JObject getSizeNodeProps(CswNbtResources CswNbtResources, Int32 SizeNodeTypeId, JObject SizeObj, bool WriteNode, out CswNbtNode SizeNode, CswPrimaryKey MaterialId = null)
        {
            JObject Ret = new JObject();

            SizeNode = CswNbtResources.Nodes.makeNodeFromNodeTypeId(SizeNodeTypeId, OverrideUniqueValidation: true);
            string UoMId = SizeObj["uom"]["id"].ToString();

            // CIS-53182: Preventative measure against the uomid being empty from client
            if (null != MaterialId && string.IsNullOrEmpty(UoMId) && false == string.IsNullOrEmpty(SizeObj["uom"]["value"].ToString()))
            {
                // Try to find the id for the unit of measure
                CswNbtUnitViewBuilder UnitViewBuilder = new CswNbtUnitViewBuilder(CswNbtResources);
                CswNbtView            UnitsView       = UnitViewBuilder.getQuantityUnitOfMeasureView(MaterialId);
                ICswNbtTree           UnitTree        = CswNbtResources.Trees.getTreeFromView(UnitsView, false, false, false);
                for (int i = 0; i < UnitTree.getChildNodeCount(); i++)
                {
                    UnitTree.goToNthChild(i);
                    if (UnitTree.getNodeNameForCurrentPosition().Equals(SizeObj["uom"]["value"].ToString()))
                    {
                        UoMId = UnitTree.getNodeIdForCurrentPosition().ToString();
                    }
                }
            }

            CswPrimaryKey UnitIdPK = CswConvert.ToPrimaryKey(UoMId);

            if (null != UnitIdPK)
            {
                SizeNode = CswNbtResources.Nodes.makeNodeFromNodeTypeId(SizeNodeTypeId, delegate(CswNbtNode NewNode)
                {
                    CswNbtObjClassSize NodeAsSize       = (CswNbtObjClassSize)NewNode;
                    NodeAsSize.InitialQuantity.Quantity = CswConvert.ToDouble(SizeObj["quantity"]["value"]);
                    NodeAsSize.InitialQuantity.UnitId   = UnitIdPK;
                    NodeAsSize.CatalogNo.Text           = SizeObj["catalogNo"]["value"].ToString();
                    NodeAsSize.QuantityEditable.Checked = CswConvert.ToTristate(SizeObj["quantityEditable"]["value"]);
                    NodeAsSize.Dispensable.Checked      = CswConvert.ToTristate(SizeObj["dispensible"]["value"]);
                    NodeAsSize.UnitCount.Value          = CswConvert.ToDouble(SizeObj["unitCount"]["value"]);
                    NodeAsSize.Material.RelatedNodeId   = MaterialId;
                });
            }
            else
            {
                SizeNode = null;
            }

            return(Ret);
        }
        public override void ReadJSON(JObject JObject, Dictionary <Int32, Int32> NodeMap, Dictionary <Int32, Int32> NodeTypeMap)
        {
            if (null != JObject[_QuantitySubField.ToXmlNodeName(true)])
            {
                Quantity = CswConvert.ToDouble(JObject[_QuantitySubField.ToXmlNodeName(true)].ToString());
            }
            if (null != JObject[_UnitNameSubField.ToXmlNodeName(true)])
            {
                CachedUnitName = JObject[_UnitNameSubField.ToXmlNodeName(true)].ToString();
            }
            //if( null != JObject[_Val_kg_SubField.ToXmlNodeName( true )] )
            //{
            //    Val_kg = CswConvert.ToDouble( JObject[_Val_kg_SubField.ToXmlNodeName( true )].ToString() );
            //}
            //if( null != JObject[_Val_Liters_SubField.ToXmlNodeName( true )] )
            //{
            //    Val_Liters = CswConvert.ToDouble( JObject[_Val_Liters_SubField.ToXmlNodeName( true )].ToString() );
            //}

            if (null != JObject[_UnitIdSubField.ToXmlNodeName(true)])
            {
                string        NodePkString = JObject[_UnitIdSubField.ToXmlNodeName(true)].ToString();
                CswPrimaryKey thisUnitId   = new CswPrimaryKey();
                bool          validPk      = thisUnitId.FromString(NodePkString);
                if (false == validPk)
                {
                    thisUnitId.TableName  = "nodes";
                    thisUnitId.PrimaryKey = CswConvert.ToInt32(NodePkString);
                }
                if (CswTools.IsPrimaryKey(thisUnitId))
                {
                    if (NodeMap != null && NodeMap.ContainsKey(thisUnitId.PrimaryKey))
                    {
                        thisUnitId.PrimaryKey = NodeMap[thisUnitId.PrimaryKey];
                    }
                    UnitId = thisUnitId;
                    JObject["destnodeid"] = UnitId.PrimaryKey.ToString();
                    //PendingUpdate = true;
                }
                else
                {
                    UnitId = null;
                }
            }
        }
 public override void ReadJSON(JObject JObject, Dictionary <Int32, Int32> NodeMap, Dictionary <Int32, Int32> NodeTypeMap)
 {
     if (null != JObject[_LowerSubField.ToXmlNodeName(true)])
     {
         Lower = CswConvert.ToDouble(JObject[_LowerSubField.ToXmlNodeName(true)]);
     }
     if (null != JObject[_TargetSubField.ToXmlNodeName(true)])
     {
         Target = CswConvert.ToDouble(JObject[_TargetSubField.ToXmlNodeName(true)]);
     }
     if (null != JObject[_UpperSubField.ToXmlNodeName(true)])
     {
         Upper = CswConvert.ToDouble(JObject[_UpperSubField.ToXmlNodeName(true)]);
     }
     if (null != JObject[_LowerInclusiveSubField.ToXmlNodeName(true)])
     {
         LowerInclusive = CswConvert.ToBoolean(JObject[_LowerInclusiveSubField.ToXmlNodeName(true)]);
     }
     if (null != JObject[_UpperInclusiveSubField.ToXmlNodeName(true)])
     {
         UpperInclusive = CswConvert.ToBoolean(JObject[_UpperInclusiveSubField.ToXmlNodeName(true)]);
     }
 }
        public CswNbtNodePropScientific(CswNbtResources CswNbtResources, CswNbtNodePropData CswNbtNodePropData, CswNbtMetaDataNodeTypeProp CswNbtMetaDataNodeTypeProp, CswNbtNode Node)
            : base(CswNbtResources, CswNbtNodePropData, CswNbtMetaDataNodeTypeProp, Node)
        {
            _BaseSubField     = ((CswNbtFieldTypeRuleScientific)_FieldTypeRule).BaseSubField;
            _ExponentSubField = ((CswNbtFieldTypeRuleScientific)_FieldTypeRule).ExponentSubField;

            // Associate subfields with methods on this object, for SetSubFieldValue()
            _SubFieldMethods.Add(_BaseSubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => Base, x => Base             = CswConvert.ToDouble(x)));
            _SubFieldMethods.Add(_ExponentSubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => Exponent, x => Exponent = CswConvert.ToInt32(x)));
        }
        public CswNbtNodePropNumericRange(CswNbtResources CswNbtResources, CswNbtNodePropData CswNbtNodePropData, CswNbtMetaDataNodeTypeProp CswNbtMetaDataNodeTypeProp, CswNbtNode Node)
            : base(CswNbtResources, CswNbtNodePropData, CswNbtMetaDataNodeTypeProp, Node)
        {
            _LowerSubField          = ((CswNbtFieldTypeRuleNumericRange)_FieldTypeRule).LowerSubField;
            _TargetSubField         = ((CswNbtFieldTypeRuleNumericRange)_FieldTypeRule).TargetSubField;
            _UpperSubField          = ((CswNbtFieldTypeRuleNumericRange)_FieldTypeRule).UpperSubField;
            _LowerInclusiveSubField = ((CswNbtFieldTypeRuleNumericRange)_FieldTypeRule).LowerInclusiveSubField;
            _UpperInclusiveSubField = ((CswNbtFieldTypeRuleNumericRange)_FieldTypeRule).UpperInclusiveSubField;
            _UnitsSubField          = ((CswNbtFieldTypeRuleNumericRange)_FieldTypeRule).UnitsSubField;

            // Associate subfields with methods on this object, for SetSubFieldValue()
            _SubFieldMethods.Add(_LowerSubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => Lower, x => Lower    = CswConvert.ToDouble(x)));
            _SubFieldMethods.Add(_TargetSubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => Target, x => Target = CswConvert.ToDouble(x)));
            _SubFieldMethods.Add(_UpperSubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => Upper, x => Upper    = CswConvert.ToDouble(x)));
            _SubFieldMethods.Add(_LowerInclusiveSubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => LowerInclusive, x => LowerInclusive = CswConvert.ToBoolean(x)));
            _SubFieldMethods.Add(_UpperInclusiveSubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => UpperInclusive, x => UpperInclusive = CswConvert.ToBoolean(x)));
            _SubFieldMethods.Add(_UnitsSubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => Units, x => Units = x));
        }
        public TierIIData getTierIIData(TierIIData.TierIIDataRequest Request)
        {
            CswArbitrarySelect TierIISelect = _CswNbtResources.makeCswArbitrarySelect("Tier II Material Select",
                                                                                      "select * from table(TIER_II_DATA_MANAGER.GET_TIER_II_DATA(" + CswConvert.ToPrimaryKey(Request.LocationId).PrimaryKey +
                                                                                      ", " + _CswNbtResources.getDbNativeDate(DateTime.Parse(Request.StartDate)) +
                                                                                      ", " + _CswNbtResources.getDbNativeDate(DateTime.Parse(Request.EndDate)) + ")) where casno is not null");
            DataTable TierIITable = TierIISelect.getTable();

            foreach (DataRow MaterialRow in TierIITable.Rows)
            {
                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                 = CswConvert.ToBoolean(MaterialRow["ehs"].ToString()),
                    TradeSecret         = CswConvert.ToBoolean(MaterialRow["tradesecret"].ToString()),
                    MaxQty              = Math.Round(CswConvert.ToDouble(MaterialRow["maxqty"]), 3),
                    MaxQtyRangeCode     = MaterialRow["maxqtyrangecode"].ToString(),
                    AverageQty          = Math.Round(CswConvert.ToDouble(MaterialRow["avgqty"]), 3),
                    AverageQtyRangeCode = MaterialRow["avgqtyrangecode"].ToString(),
                    DaysOnSite          = CswConvert.ToInt32(MaterialRow["daysonsite"]),
                    Unit                = "lb"
                };
                CswCommaDelimitedString Hazards = new CswCommaDelimitedString();
                Hazards.FromString(MaterialRow["hazardcategories"].ToString());
                foreach (String Hazard in Hazards)
                {
                    Material.HazardCategories.Add(Hazard);
                }
                int ContainerPropRows;
                CswCommaDelimitedString Pressures = new CswCommaDelimitedString();
                Pressures.FromString(MaterialRow["pressure"].ToString());
                ContainerPropRows = Pressures.Count;
                CswCommaDelimitedString Temperatures = new CswCommaDelimitedString();
                Temperatures.FromString(MaterialRow["temperature"].ToString());
                ContainerPropRows = Temperatures.Count > ContainerPropRows ? Temperatures.Count : ContainerPropRows;
                CswCommaDelimitedString UseTypes = new CswCommaDelimitedString();
                UseTypes.FromString(MaterialRow["usetype"].ToString());
                ContainerPropRows = UseTypes.Count > ContainerPropRows ? UseTypes.Count : ContainerPropRows;
                for (int i = 0; i < ContainerPropRows; i++)
                {
                    int p = Pressures.Count - 1 < i ? Pressures.Count : i;
                    int t = Pressures.Count - 1 < i ? Pressures.Count : i;
                    int u = Pressures.Count - 1 < i ? Pressures.Count : i;
                    TierIIData.StorageCodes StorageCodes = new TierIIData.StorageCodes
                    {
                        Pressure    = Pressures[p],
                        Temperature = Temperatures[t],
                        UseType     = UseTypes[u]
                    };
                    Material.Storage.Add(StorageCodes);
                }
                CswCommaDelimitedString Locations = new CswCommaDelimitedString();
                Locations.FromString(MaterialRow["storagelocations"].ToString());
                foreach (String Location in Locations)
                {
                    Material.Locations.Add(new TierIIData.StorageLocations
                    {
                        Location = Location
                    });
                }
                Data.Materials.Add(Material);
            }

            return(Data);
        }
        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);
        }
Beispiel #15
0
        }//_transfer()

        private void _dispense(string operation, string barcode, JObject update, CswNbtObjClassBatchOp BatchNode)
        {
            try
            {
                string                    uom             = update["uom"].ToString().ToLower();
                CswPrimaryKey             uomId           = null;
                CswNbtMetaDataObjectClass UnitOfMeasureOC = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.UnitOfMeasureClass);
                foreach (CswNbtObjClassUnitOfMeasure currentUnitOfMeasureNode in UnitOfMeasureOC.getNodes(false, false, false, true))
                {
                    string unitName = currentUnitOfMeasureNode.NodeName.ToLower();
                    if (unitName == uom)
                    {
                        uomId = currentUnitOfMeasureNode.NodeId;
                    }
                }

                if (null != uomId)
                {
                    CswNbtObjClassContainer containerNode = _getNodeFromBarcode(barcode, CswEnumNbtObjectClass.ContainerClass, CswNbtObjClassContainer.PropertyName.Barcode);
                    if (null != containerNode)
                    {
                        containerNode.DispenseOut(CswEnumNbtContainerDispenseType.Dispense, CswConvert.ToDouble(update["qty"]), uomId);
                        containerNode.postChanges(false);
                    }
                    else
                    {
                        string msg = _generateErrorMessage(operation, barcode, new Dictionary <string, string> {
                            { "Dispense Data", update.ToString() }
                        }, "A container with barcode " + barcode + " does not exist.");
                        _storeError(BatchNode, msg);
                    }
                }
                else
                {
                    string msg = _generateErrorMessage(operation, barcode, new Dictionary <string, string> {
                        { "Dispense Data", update.ToString() }
                    }, "The UOM of " + uom + " that was provided does not exist.");
                    _storeError(BatchNode, msg);
                }
            }
            catch (Exception e)
            {
                string msg = "The dispense operation failed for the container barcode " + barcode + "with exception: " + e;
                _storeError(BatchNode, msg);
            }
        }//_dispense()
        public HMISData getHMISData(HMISData.HMISDataRequest Request)
        {
            HMISData      Data          = new HMISData();
            CswPrimaryKey ControlZoneId = null;

            if (false == string.IsNullOrEmpty(Request.ControlZoneId))
            {
                ControlZoneId = CswConvert.ToPrimaryKey(Request.ControlZoneId);
            }
            else if (false == string.IsNullOrEmpty(Request.ControlZone))
            {
                if (CswTools.IsInteger(Request.ControlZone))
                {
                    ControlZoneId = new CswPrimaryKey("nodes", CswConvert.ToInt32(Request.ControlZone));
                }
                else
                {
                    CswNbtView  ControlZoneView = getControlZonesView(Request.ControlZone);
                    ICswNbtTree ControlZoneTree = _CswNbtResources.Trees.getTreeFromView(ControlZoneView, RequireViewPermissions: false, IncludeSystemNodes: true, IncludeHiddenNodes: true);
                    if (ControlZoneTree.getChildNodeCount() > 0)
                    {
                        ControlZoneTree.goToNthChild(0);
                        ControlZoneId = ControlZoneTree.getNodeIdForCurrentPosition();
                    }
                }
            }

            if (CswTools.IsPrimaryKey(ControlZoneId))
            {
                Data.ControlZone = _CswNbtResources.Nodes.getNodeName(ControlZoneId);

                string HMISSql = @"with loc as (select n.nodeid
                                                  from nodes n
                                                  join nodetypes t on t.nodetypeid = n.nodetypeid
                                                  join object_class oc on t.objectclassid = oc.objectclassid
                                                  join (select j.nodeid, j.field1_fk 
                                                          from object_class_props ocp  
                                                          join nodetype_props ntp on ocp.objectclasspropid = ntp.objectclasspropid 
                                                          join jct_nodes_props j on ntp.nodetypepropid = j.nodetypepropid
                                                         where ocp.propname = 'Control Zone'
                                                       ) cz on (cz.nodeid = n.nodeid)
                                                 where oc.objectclass = 'LocationClass'
                                                   and cz.field1_fk = " + ControlZoneId.PrimaryKey + @"
                                               ),
                                        mat as (select n.nodeid, n.nodename materialname, hc.clobdata hazardclasses, sf.gestaltsearch specialflags, ps.field1 physstate
                                                  from nodes n
                                                  join nodetypes t on t.nodetypeid = n.nodetypeid
                                                  join object_class oc on t.objectclassid = oc.objectclassid
                                                  join (select j.nodeid, j.clobdata
                                                          from object_class_props ocp  
                                                          join nodetype_props ntp on ocp.objectclasspropid = ntp.objectclasspropid 
                                                          join jct_nodes_props j on ntp.nodetypepropid = j.nodetypepropid
                                                         where ocp.propname = 'Hazard Classes'
                                                       ) hc on (hc.nodeid = n.nodeid)
                                                  join (select j.nodeid, j.gestaltsearch 
                                                          from object_class_props ocp  
                                                          join nodetype_props ntp on ocp.objectclasspropid = ntp.objectclasspropid 
                                                          join jct_nodes_props j on ntp.nodetypepropid = j.nodetypepropid
                                                         where ocp.propname = 'Special Flags'
                                                       ) sf on (sf.nodeid = n.nodeid)
                                                  join (select j.nodeid, j.field1
                                                          from object_class_props ocp  
                                                          join nodetype_props ntp on ocp.objectclasspropid = ntp.objectclasspropid 
                                                          join jct_nodes_props j on ntp.nodetypepropid = j.nodetypepropid
                                                         where ocp.propname = 'Physical State'
                                                       ) ps on (ps.nodeid = n.nodeid)
                                                 where oc.objectclass = 'ChemicalClass'
                                                   and (sf.gestaltsearch is null or sf.gestaltsearch not like '%not reportable%')";
                if (string.IsNullOrEmpty(Request.Class))
                {
                    HMISSql += "   and hc.clobdata is not null";
                }
                else
                {
                    HMISSql += "   and hc.clobdata like '%" + Request.Class + @"%'";
                }
                HMISSql += @"                ),
                                       cont as (select SUM(q.field2_numeric) total_qty_kg, 
                                                       SUM(q.field3_numeric) total_qty_lt, 
                                                       ut.field1 usetype, 
                                                       m.field1_fk materialid
                                                  from nodes n
                                                  join nodetypes t on t.nodetypeid = n.nodetypeid
                                                  join object_class oc on t.objectclassid = oc.objectclassid
                                                  join (select j.nodeid, j.field1_fk 
                                                          from object_class_props ocp  
                                                          join nodetype_props ntp on ocp.objectclasspropid = ntp.objectclasspropid 
                                                          join jct_nodes_props j on ntp.nodetypepropid = j.nodetypepropid
                                                         where ocp.propname = 'Location'
                                                       ) l on (l.nodeid = n.nodeid)
                                                  join (select j.nodeid, j.field2_numeric, j.field3_numeric 
                                                          from object_class_props ocp  
                                                          join nodetype_props ntp on ocp.objectclasspropid = ntp.objectclasspropid 
                                                          join jct_nodes_props j on ntp.nodetypepropid = j.nodetypepropid
                                                         where ocp.propname = 'Quantity'
                                                       ) q on (q.nodeid = n.nodeid)
                                                  join (select j.nodeid, j.field1 
                                                          from object_class_props ocp  
                                                          join nodetype_props ntp on ocp.objectclasspropid = ntp.objectclasspropid 
                                                          join jct_nodes_props j on ntp.nodetypepropid = j.nodetypepropid
                                                         where ocp.propname = 'Use Type'
                                                       ) ut on (ut.nodeid = n.nodeid)
                                                  join (select j.nodeid, j.field1_fk 
                                                          from object_class_props ocp  
                                                          join nodetype_props ntp on ocp.objectclasspropid = ntp.objectclasspropid 
                                                          join jct_nodes_props j on ntp.nodetypepropid = j.nodetypepropid
                                                         where ocp.propname = 'Material'
                                                       ) m on (m.nodeid = n.nodeid)
                                                 where oc.objectclass = 'ContainerClass'
                                                   and ut.field1 is not null
                                                   and l.field1_fk in (select nodeid from loc) 
                                                   and (q.field2_numeric > 0 
                                                     or q.field3_numeric > 0)
                                                 group by ut.field1, m.field1_fk
                                               )
                                   select c.*, mat.hazardclasses, mat.specialflags, mat.materialname, mat.physstate
                                     from cont c
                                     join mat on (c.materialid = mat.nodeid)";
                CswArbitrarySelect HMISSelect = _CswNbtResources.makeCswArbitrarySelect("HMIS_Select", HMISSql);
                DataTable          HMISTable  = HMISSelect.getTable();

                if (string.IsNullOrEmpty(Request.Class))
                {
                    // Get totals for all classes
                    _setFireClasses(ControlZoneId, Data);

                    foreach (DataRow row in HMISTable.Rows)
                    {
                        CswCommaDelimitedString HazardClasses = new CswCommaDelimitedString();
                        HazardClasses.FromString(CswConvert.ToString(row["hazardclasses"]));
                        if (HazardClasses.Contains("FL-1A") || HazardClasses.Contains("FL-1B") || HazardClasses.Contains("FL-1C"))
                        {
                            HazardClasses.Add("FL-Comb");
                        }
                        foreach (String HazardClass in HazardClasses)
                        {
                            HMISData.HMISMaterial HMISMaterial = Data.Materials.FirstOrDefault(EmptyHazardClass => EmptyHazardClass.HazardClass == HazardClass);
                            if (null != HMISMaterial)  //This would only be null if the Material's HazardClass options don't match the Default FireClass nodes
                            {
                                _addQuantityDataToHMISMaterial(HMISMaterial,
                                                               CswConvert.ToString(row["usetype"]),
                                                               CswConvert.ToDouble(row["total_qty_kg"]),
                                                               CswConvert.ToDouble(row["total_qty_lt"]),
                                                               CswConvert.ToString(row["physstate"]),
                                                               new CswPrimaryKey("nodes", CswConvert.ToInt32(row["materialid"])));
                            }
                        }
                    } // foreach( DataRow row in HMISTable )
                }     // if( string.IsNullOrEmpty( Request.Class ) )
                else
                {
                    // Get material information for one class
                    foreach (DataRow row in HMISTable.Rows)
                    {
                        HMISData.HMISMaterial NewMaterial = new HMISData.HMISMaterial
                        {
                            Material    = CswConvert.ToString(row["materialname"]),
                            NodeId      = CswConvert.ToInt32(row["materialid"]),
                            HazardClass = Request.Class
                        };
                        _addQuantityDataToHMISMaterial(NewMaterial,
                                                       CswConvert.ToString(row["usetype"]),
                                                       CswConvert.ToDouble(row["total_qty_kg"]),
                                                       CswConvert.ToDouble(row["total_qty_lt"]),
                                                       CswConvert.ToString(row["physstate"]),
                                                       new CswPrimaryKey("nodes", CswConvert.ToInt32(row["materialid"])));
                        Data.Materials.Add(NewMaterial);
                    }
                } // if-else( string.IsNullOrEmpty( Request.Class ) )
            }     // if( CswTools.IsPrimaryKey( ControlZoneId ) )
            return(Data);
        }
Beispiel #17
0
        public CswNbtNodePropNumber(CswNbtResources CswNbtResources, CswNbtNodePropData CswNbtNodePropData, CswNbtMetaDataNodeTypeProp CswNbtMetaDataNodeTypeProp, CswNbtNode Node)
            : base(CswNbtResources, CswNbtNodePropData, CswNbtMetaDataNodeTypeProp, Node)
        {
            _ValueSubField = ((CswNbtFieldTypeRuleNumber)_FieldTypeRule).ValueSubField;

            // Associate subfields with methods on this object, for SetSubFieldValue()
            _SubFieldMethods.Add(_ValueSubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => Value, x => Value = CswConvert.ToDouble(x)));
        }
        public static void getTimelines(ICswResources CswResources, CswNbtSchedServiceTimeLineReturn Return, CswNbtSchedServiceTimeLineRequest Request)
        {
            CswNbtResources NbtResources = (CswNbtResources)CswResources;

            DateTime StartDate = new DateTime();
            int      counter   = 0;

            CswColorGenerator ColorGenerator = new CswColorGenerator();

            int SeriesNo = 30;

            Dictionary <string, Series> TimeLineData = new Dictionary <string, Series>();
            HashSet <string>            seen         = new HashSet <string>();

            string LogFileLocation = NbtResources.SetupVbls[CswEnumSetupVariableNames.LogFileLocation];

            _getLogFiles(NbtResources, Return, LogFileLocation);   //Order the log files by last modified date

            //Case 30403 - if the current user is not ChemSW_Admin, scope timeline to the users schema
            if (NbtResources.CurrentNbtUser.Username != CswAuthenticator.ChemSWAdminUsername)
            {
                Request.FilterSchemaTo = NbtResources.AccessId;
            }

            if (Return.Data.FilterData.LogFiles.Count > 0)
            {
                //If no log file is selected, default to the last log file modified
                string       selectedFile = String.IsNullOrEmpty(Request.SelectedLogFile) ? Return.Data.FilterData.LogFiles[0] : Request.SelectedLogFile;
                StreamReader file         = new StreamReader(LogFileLocation + @"\" + selectedFile);
                string       line;
                while ((line = file.ReadLine()) != null)
                {
                    line = line.Replace("\"", "");
                    string[] splitLine = line.Split(',');
                    string   MsgType   = splitLine[0];

                    if ((MsgType.Equals("PerOp") || MsgType.Equals("Error")))
                    {
                        string Schema        = splitLine[1];
                        string StartTime     = splitLine[20];
                        string OpName        = splitLine[23].Split(':')[0]; //this is something like "GenNode: Execution" and all we want is "GenNode"
                        double ExecutionTime = CswConvert.ToDouble(splitLine[28]);
                        string ErrMsg        = splitLine[9];

                        if (MsgType.Equals("Error"))
                        {
                            OpName        = "Error";
                            ExecutionTime = double.MinValue;
                        }
                        string LegendName = Schema + " " + OpName;

                        _populateFilterData(NbtResources, Return, OpName, Schema, seen);

                        DateTime thisStartDate = CswConvert.ToDateTime(StartTime);

                        DateTime FilterDateStart = CswConvert.ToDateTime(Request.FilterStartTimeTo);
                        DateTime FilterDateEnd   = CswConvert.ToDateTime(Request.FilterEndTimeTo);
                        CswCommaDelimitedString FilterSchemas = new CswCommaDelimitedString();
                        FilterSchemas.FromString(Request.FilterSchemaTo);
                        CswCommaDelimitedString FilterOps = new CswCommaDelimitedString();
                        FilterOps.FromString(Request.FilterOpTo);

                        if (((thisStartDate >= FilterDateStart && thisStartDate <= FilterDateEnd) || (DateTime.MinValue == FilterDateStart && DateTime.MinValue == FilterDateEnd)) &&
                            (FilterSchemas.Contains(Schema) || String.IsNullOrEmpty(Request.FilterSchemaTo)) &&
                            (FilterOps.Contains(OpName) || String.IsNullOrEmpty(Request.FilterOpTo)))
                        {
                            if (FilterSchemas.IsEmpty || FilterOps.IsEmpty)  //If no schema filter is set we want to generate a timeline of each schema + all the rules that ran
                            {
                                if (FilterOps.IsEmpty)
                                {
                                    if (MsgType.Equals("Error"))
                                    {
                                        //If we're mashing all schema errors together, we do not show what the msg or schema was was since there are probably many, just that an error occured.
                                        LegendName = "Error";
                                        OpName     = "";
                                        ErrMsg     = "";
                                        Schema     = "";
                                    }
                                    else
                                    {
                                        //If we're mashing all schema together, we don't care what op ran since there are many, just show that this schema was running something
                                        LegendName = Schema;
                                        OpName     = "";
                                    }
                                }
                                else
                                {
                                    //If no schema is selected, but there are Op filters, we mash the Ops on each Schema together
                                    LegendName = OpName;
                                    Schema     = "";
                                }
                            }

                            if (0 == counter)
                            {
                                StartDate = CswConvert.ToDateTime(StartTime);
                            }
                            counter++;

                            double DataStartS = (thisStartDate - StartDate).TotalMilliseconds / 1000;
                            double DataEndS   = double.MinValue;
                            if (MsgType.Equals("PerOp"))
                            {
                                DataEndS = DataStartS + ExecutionTime / 1000;
                            }

                            Series ThisSeries;
                            if (TimeLineData.ContainsKey(LegendName))
                            {
                                ThisSeries = TimeLineData[LegendName];
                            }
                            else
                            {
                                ThisSeries = new Series()
                                {
                                    label      = LegendName,
                                    SchemaName = Schema,
                                    OpName     = OpName,
                                    SeriesNo   = SeriesNo,
                                    ErrorMsg   = ErrMsg
                                };
                                TimeLineData.Add(LegendName, ThisSeries);
                                SeriesNo += 90;
                            }
                            _processData(ThisSeries, DataStartS, DataEndS, ExecutionTime, thisStartDate.ToString(), ColorGenerator);
                        }
                    } //if( splitLine.Length >= 28 && splitLine[0].Equals( "PerOp" ) )
                }     // while( ( line = file.ReadLine() ) != null && counter <= maxLines )

                foreach (Series series in TimeLineData.Values)
                {
                    Return.Data.Series.Add(series);
                }
            }
        }//getTimelines()
        public CswNbtNodePropMTBF(CswNbtResources CswNbtResources, CswNbtNodePropData CswNbtNodePropData, CswNbtMetaDataNodeTypeProp CswNbtMetaDataNodeTypeProp, CswNbtNode Node)
            : base(CswNbtResources, CswNbtNodePropData, CswNbtMetaDataNodeTypeProp, Node)
        {
            _StartDateTimeSubField = ((CswNbtFieldTypeRuleMTBF)_FieldTypeRule).StartDateTimeSubField;
            _UnitsSubField         = ((CswNbtFieldTypeRuleMTBF)_FieldTypeRule).UnitsSubField;
            _ValueSubField         = ((CswNbtFieldTypeRuleMTBF)_FieldTypeRule).ValueSubField;

            if (string.IsNullOrEmpty(Units))
            {
                Units = "days";
            }

            // Associate subfields with methods on this object, for SetSubFieldValue()
            _SubFieldMethods.Add(_StartDateTimeSubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => StartDateTime, x => StartDateTime = CswConvert.ToDateTime(x)));
            _SubFieldMethods.Add(_UnitsSubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => Units, x => Units             = CswConvert.ToString(x)));
            _SubFieldMethods.Add(_ValueSubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => CachedValue, x => CachedValue = CswConvert.ToDouble(x)));
        }
        public CswNbtNodePropQuantity(CswNbtResources CswNbtResources, CswNbtNodePropData CswNbtNodePropData, CswNbtMetaDataNodeTypeProp CswNbtMetaDataNodeTypeProp, CswNbtNode Node)
            : base(CswNbtResources, CswNbtNodePropData, CswNbtMetaDataNodeTypeProp, Node)
        {
            _QuantitySubField    = ((CswNbtFieldTypeRuleQuantity)_FieldTypeRule).QuantitySubField;
            _Val_kg_SubField     = ((CswNbtFieldTypeRuleQuantity)_FieldTypeRule).Val_kg_SubField;
            _Val_Liters_SubField = ((CswNbtFieldTypeRuleQuantity)_FieldTypeRule).Val_Liters_SubField;
            _UnitNameSubField    = ((CswNbtFieldTypeRuleQuantity)_FieldTypeRule).UnitNameSubField;
            _UnitIdSubField      = ((CswNbtFieldTypeRuleQuantity)_FieldTypeRule).UnitIdSubField;

            // Associate subfields with methods on this object, for SetSubFieldValue()
            _SubFieldMethods.Add(_QuantitySubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => Quantity, x => Quantity             = CswConvert.ToDouble(x)));
            _SubFieldMethods.Add(_Val_kg_SubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => Val_kg, x => Val_kg                  = CswConvert.ToDouble(x)));
            _SubFieldMethods.Add(_Val_Liters_SubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => Val_Liters, x => Val_Liters      = CswConvert.ToDouble(x)));
            _SubFieldMethods.Add(_UnitNameSubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => CachedUnitName, x => CachedUnitName = CswConvert.ToString(x)));
            _SubFieldMethods.Add(_UnitIdSubField.Name, new Tuple <Func <dynamic>, Action <dynamic> >(() => UnitId, x => UnitId = CswConvert.ToPrimaryKey(x)));
        }
        } // load()

        private void loadRelationshipRecursive(CswNbtViewRelationship Relationship, bool RequireViewPermissions, bool GroupBySiblings,
                                               IEnumerable <CswPrimaryKey> ParentNodeIds = null, Int32 ResultsLimit = Int32.MinValue)
        {
            CswNbtNodeKey PriorCurrentNodeKey = _CswNbtTree.getNodeKeyForCurrentPosition();

            // Nodes and Properties
            DataTable          NodesTable   = new DataTable();
            CswArbitrarySelect ResultSelect = _makeNodeSql(Relationship, ParentNodeIds);

            Int32 thisResultLimit = _CswNbtResources.TreeViewResultLimit;

            if (ResultsLimit != Int32.MinValue)
            {
                thisResultLimit = ResultsLimit;
            }

            if (Relationship.Properties.Count > 0)
            {
                thisResultLimit = thisResultLimit * Relationship.Properties.Count;
            }

            CswTimer SqlTimer = new CswTimer();

            try
            {
                NodesTable = ResultSelect.getTable(0, thisResultLimit, false);
            }
            catch (Exception ex)
            {
                throw new CswDniException(CswEnumErrorType.Error, "Invalid View", "_getNodes() attempted to run invalid SQL: " + ResultSelect.Sql, ex);
            }
            _CswNbtResources.CswLogger.TreeLoaderSQLTime += SqlTimer.ElapsedDurationInMilliseconds;

            if (SqlTimer.ElapsedDurationInSeconds > 2)
            {
                _CswNbtResources.logMessage("Tree View SQL required longer than 2 seconds to run: " + ResultSelect.Sql);
            }

            Int32 PriorNodeId       = Int32.MinValue;
            Int32 PriorParentNodeId = Int32.MinValue;
            Collection <CswPrimaryKey> KeysThisLevel  = new Collection <CswPrimaryKey>();
            Collection <CswNbtNodeKey> NewNodeKeys    = new Collection <CswNbtNodeKey>();
            Collection <CswNbtNodeKey> ParentNodeKeys = null;

            foreach (DataRow NodesRow in NodesTable.Rows)
            {
                Int32         ThisNodeId       = CswConvert.ToInt32(NodesRow["nodeid"]);
                CswPrimaryKey ThisNodePk       = new CswPrimaryKey("nodes", ThisNodeId);
                Int32         ThisParentNodeId = Int32.MinValue;
                if (NodesTable.Columns.Contains("parentnodeid"))
                {
                    ThisParentNodeId = CswConvert.ToInt32(NodesRow["parentnodeid"]);
                }
                Int32 ThisNodeTypeId    = CswConvert.ToInt32(NodesRow["nodetypeid"]);
                bool  ThisNodeFavorited = false == String.IsNullOrEmpty(NodesRow["userid"].ToString());

                // Verify permissions
                // this could be a performance problem
                CswNbtMetaDataNodeType ThisNodeType = _CswNbtResources.MetaData.getNodeType(ThisNodeTypeId);
                if (false == RequireViewPermissions ||
                    (_CswNbtResources.Permit.canAnyTab(CswEnumNbtNodeTypePermission.View, ThisNodeType, _RunAsUser) &&
                     _CswNbtResources.Permit.isNodeWritable(CswEnumNbtNodeTypePermission.View, ThisNodeType, ThisNodePk, _RunAsUser)))
                {
                    // Handle property multiplexing
                    // This assumes that property rows for the same nodeid are next to one another
                    if (ThisNodeId != PriorNodeId || ThisParentNodeId != PriorParentNodeId)
                    {
                        PriorNodeId       = ThisNodeId;
                        PriorParentNodeId = ThisParentNodeId;
                        NewNodeKeys       = new Collection <CswNbtNodeKey>();
                        Collection <CswNbtNodeKey> ThisNewNodeKeys = new Collection <CswNbtNodeKey>();
                        ParentNodeKeys = new Collection <CswNbtNodeKey>();

                        // Handle ResultMode.Disabled on filters
                        bool Included = true;
                        foreach (DataColumn Column in NodesRow.Table.Columns)
                        {
                            if (Column.ColumnName.StartsWith("INCLUDED"))
                            {
                                string Conjunction = Column.ColumnName.Substring("INCLUDED".Length);
                                if (Conjunction.StartsWith("OR"))
                                {
                                    Included = Included || CswConvert.ToBoolean(NodesRow[Column]);
                                }
                                else
                                {
                                    Included = Included && CswConvert.ToBoolean(NodesRow[Column]);
                                }
                            }
                        }
                        bool   UseGroupBy = Relationship.GroupByPropId != Int32.MinValue;
                        string GroupName  = string.Empty;
                        if (UseGroupBy)
                        {
                            GroupName = CswConvert.ToString(NodesRow["groupname"]);
                            if (GroupName == string.Empty)
                            {
                                GroupName = "[blank]";
                            }
                        }
                        else if (GroupBySiblings)
                        {
                            UseGroupBy = true;
                            GroupName  = CswConvert.ToString(NodesRow["nodetypename"]);
                        }

                        if (NodesTable.Columns.Contains("parentnodeid"))
                        {
                            CswPrimaryKey ParentNodePk = new CswPrimaryKey("nodes", CswConvert.ToInt32(NodesRow["parentnodeid"]));

                            // We can't use getNodeKeyByNodeId, because there may be more instances of this node at different places in the tree
                            //ParentNodeKey = _CswNbtTree.getNodeKeyByNodeId( ParentNodeId );
                            ParentNodeKeys = _CswNbtTree.getNodeKeysByNodeIdAndViewNode(ParentNodePk, Relationship.Parent);

                            if (ParentNodeKeys.Count == 0)
                            {
                                // If the parent isn't in the tree, don't add the child
                                PriorNodeId = Int32.MinValue;   // case 24788
                            }
                            else
                            {
                                foreach (CswNbtNodeKey ParentNodeKey in ParentNodeKeys)
                                {
                                    _CswNbtTree.makeNodeCurrent(ParentNodeKey);
                                    Int32 ChildCount = _CswNbtTree.getChildNodeCount();
                                    ThisNewNodeKeys = _CswNbtTree.loadNodeAsChildFromRow(ParentNodeKey, NodesRow, UseGroupBy, GroupName, Relationship, ChildCount + 1, Included, ThisNodeFavorited);
                                    foreach (CswNbtNodeKey ThisNewNodeKey in ThisNewNodeKeys)
                                    {
                                        NewNodeKeys.Add(ThisNewNodeKey);
                                        KeysThisLevel.Add(ThisNewNodeKey.NodeId);
                                    }
                                } // foreach( CswNbtNodeKey ParentNodeKey in ParentNodeKeys )
                            }
                        }         // if( NodesTable.Columns.Contains( "parentnodeid" ) )
                        else
                        {
                            Int32 ChildCount = _CswNbtTree.getChildNodeCount();
                            ThisNewNodeKeys = _CswNbtTree.loadNodeAsChildFromRow(null, NodesRow, UseGroupBy, GroupName, Relationship, ChildCount + 1, Included, ThisNodeFavorited);
                            foreach (CswNbtNodeKey ThisNewNodeKey in ThisNewNodeKeys)
                            {
                                NewNodeKeys.Add(ThisNewNodeKey);
                                KeysThisLevel.Add(ThisNewNodeKey.NodeId);
                            }
                        } // if( AddChild )
                    }     // if( ThisNodeId != PriorNodeId )

                    // This assumes that property rows for the same nodeid are next to one another
                    // It also assumes that loadNodeAsChildFromRow() made the node current
                    if (NewNodeKeys.Count > 0 && NodesTable.Columns.Contains("jctnodepropid"))
                    {
                        foreach (CswNbtNodeKey NewNodeKey in NewNodeKeys)
                        {
                            _CswNbtTree.makeNodeCurrent(NewNodeKey);
                            _CswNbtTree.addProperty(CswConvert.ToInt32(NodesRow["nodetypepropid"]),
                                                    CswConvert.ToInt32(NodesRow["objectclasspropid"]),
                                                    CswConvert.ToInt32(NodesRow["jctnodepropid"]),
                                                    NodesRow["propname"].ToString(),
                                                    NodesRow["objectclasspropname"].ToString(),
                                                    NodesRow["gestalt"].ToString(),
                                                    CswConvert.ToString(NodesRow["fieldtype"]),
                                                    CswConvert.ToString(NodesRow["field1"]),
                                                    CswConvert.ToString(NodesRow["field2"]),
                                                    CswConvert.ToInt32(NodesRow["field1_fk"]),
                                                    CswConvert.ToDouble(NodesRow["field1_numeric"]),
                                                    CswConvert.ToBoolean(NodesRow["hidden"]),
                                                    CswConvert.ToString(NodesRow["field1_big"]));
                        } // foreach( CswNbtNodeKey NewNodeKey in NewNodeKeys )
                        if (ParentNodeKeys.Count > 0)
                        {
                            _CswNbtTree.makeNodeCurrent(ParentNodeKeys[0]);
                        }
                        else
                        {
                            _CswNbtTree.goToRoot();
                        }
                    } // if( NewNodeKeys != null && NodesTable.Columns.Contains( "jctnodepropid" ) )
                }     // if( false == RequireViewPermissions || _CswNbtResources.Permit.can( CswEnumNbtNodeTypePermission.View, ThisNodeType, true, null, _RunAsUser ) )
            }         // foreach(DataRow NodesRow in NodesTable.Rows)

            if (KeysThisLevel.Count > 0)  // only recurse if there are results
            {
                // Recurse
                foreach (CswNbtViewRelationship ChildRelationship in Relationship.ChildRelationships)
                {
                    bool ContinueGroupingBySibling = (_View.GroupBySiblings && Relationship.ChildRelationships.Count > 1);
                    loadRelationshipRecursive(ChildRelationship, RequireViewPermissions, ContinueGroupingBySibling, KeysThisLevel);
                }

                // case 24678 - Mark truncated results
                if (KeysThisLevel.Count == thisResultLimit)
                {
                    //if( ParentNodeKeys != null && ParentNodeKeys.Count > 0 )
                    //{
                    //    foreach( CswNbtNodeKey ParentNodeKey in ParentNodeKeys )
                    //    {
                    //        // assume truncation on every potential parent
                    //        _CswNbtTree.makeNodeCurrent( ParentNodeKey );
                    //        _CswNbtTree.goToParentNode();
                    //        for( Int32 c = 0; c < _CswNbtTree.getChildNodeCount(); c++ )
                    //        {
                    //            _CswNbtTree.goToNthChild( c );
                    //            _CswNbtTree.setCurrentNodeChildrenTruncated( true );
                    //            _CswNbtTree.goToParentNode();
                    //        }
                    //    }
                    //}
                    //else
                    //{
                    _CswNbtTree.goToRoot();
                    _CswNbtTree.setCurrentNodeChildrenTruncated(true);
                    //}
                } // if( NodesTable.Rows.Count == thisResultLimit )
            }     // if( NodesTable.Rows.Count > 0 )

            _CswNbtTree.makeNodeCurrent(PriorCurrentNodeKey);
        } // loadRelationshipRecursive()
Beispiel #22
0
 public ContainerData getContainerStatistics(ContainerData.ReconciliationRequest Request)
 {
     for (int i = 0; i < CswEnumNbtContainerLocationStatusOptions._All.Count(); i++)
     {
         Data.ContainerStatistics.Add(new ContainerData.ReconciliationStatistics());
         Data.ContainerStatistics[i].ContainerCount = 0;
         Data.ContainerStatistics[i].AmountScanned  = 0;
         Data.ContainerStatistics[i].Status         = CswEnumNbtContainerLocationStatusOptions._All.ToArray()[i].ToString();
     }
     _setContainersTree(Request);
     if (ContainersTree.getChildNodeCount() > 0)
     {
         Collection <CswPrimaryKey> AllLocationIds     = new Collection <CswPrimaryKey>();
         Collection <CswPrimaryKey> ScannedLocationIds = new Collection <CswPrimaryKey>();
         for (int i = 0; i < ContainersTree.getChildNodeCount(); i++) //Location Nodes
         {
             ContainersTree.goToNthChild(i);
             AllLocationIds.Add(ContainersTree.getNodeIdForCurrentPosition());
             if (ContainersTree.getChildNodeCount() > 0)
             {
                 for (int j = 0; j < ContainersTree.getChildNodeCount(); j++) //Container Nodes
                 {
                     ContainersTree.goToNthChild(j);
                     CswNbtTreeNodeProp DisposedProp = ContainersTree.getChildNodePropsOfNode().FirstOrDefault(p => p.ObjectClassPropName == CswNbtObjClassContainer.PropertyName.Disposed);
                     if (ContainersTree.getChildNodeCount() > 0) //ContainerLocation Nodes
                     {
                         CswNbtObjClassContainerLocation ContainerLocationNode = _getMostRelevantContainerLocation();
                         if (null != ContainerLocationNode && _isTypeEnabled(ContainerLocationNode.Type.Value, Request))
                         {
                             _incrementContainerCount(Data.ContainerStatistics,
                                                      ContainerLocationNode.Status.Value,
                                                      ContainerLocationNode.Type.Value);
                             if (ContainerLocationNode.Type.Value == CswEnumNbtContainerLocationTypeOptions.ReconcileScans.ToString())
                             {
                                 ScannedLocationIds.Add(ContainerLocationNode.Location.SelectedNodeId);
                             }
                         }
                         else if (null != DisposedProp && false == CswConvert.ToBoolean(DisposedProp.Field1))
                         {
                             _incrementContainerCount(Data.ContainerStatistics, CswEnumNbtContainerLocationStatusOptions.NotScanned.ToString());
                         }
                     }
                     else
                     {
                         _incrementContainerCount(Data.ContainerStatistics, CswEnumNbtContainerLocationStatusOptions.NotScanned.ToString());
                     }
                     ContainersTree.goToParentNode();
                 }
             }
             ContainersTree.goToParentNode();
         }
         if (_isTypeEnabled(CswEnumNbtContainerLocationTypeOptions.ReconcileScans.ToString(), Request))
         {
             foreach (CswPrimaryKey LocationId in AllLocationIds)
             {
                 if (false == ScannedLocationIds.Contains(LocationId))
                 {
                     Data.UnscannedLocations.Add(_makeUnscannedLocation(LocationId));
                 }
             }
         }
     }
     foreach (CswNbtObjClassContainerLocation OutOfScopeScan in _getRelevantScansOutsideLocationScope(Request).Values)
     {
         _incrementContainerCount(Data.ContainerStatistics, CswEnumNbtContainerLocationStatusOptions.WrongLocation.ToString());
     }
     foreach (ContainerData.ReconciliationStatistics Stat in Data.ContainerStatistics)
     {
         if (Stat.ContainerCount > 0)
         {
             Stat.PercentScanned = CswConvert.ToDouble(Stat.AmountScanned) / CswConvert.ToDouble(Stat.ContainerCount) * 100.0;
         }
         else
         {
             Stat.PercentScanned = 0.0;
         }
     }
     return(Data);
 }
 public override void ReadJSON(JObject JObject, Dictionary <Int32, Int32> NodeMap, Dictionary <Int32, Int32> NodeTypeMap)
 {
     Base     = CswConvert.ToDouble(JObject[_BaseSubField.ToXmlNodeName(true)]);
     Exponent = CswConvert.ToInt32(JObject[_ExponentSubField.ToXmlNodeName(true)]);
 }