Example #1
0
        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);
        }
        public override void update()
        {
            CswNbtMetaDataObjectClass ComponentOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass(CswEnumNbtObjectClass.MaterialComponentClass);

            CswNbtMetaDataObjectClassProp oldLowOCP        = ComponentOC.getObjectClassProp(oldLowPercentageValue);
            CswNbtMetaDataObjectClassProp oldTargetOCP     = ComponentOC.getObjectClassProp(oldTargetPercentageValue);
            CswNbtMetaDataObjectClassProp oldHighOCP       = ComponentOC.getObjectClassProp(oldHighPercentageValue);
            CswNbtMetaDataObjectClassProp oldPercentageOCP = ComponentOC.getObjectClassProp(oldPercentageValue);

            if (null != oldLowOCP)
            {
                // Copy values from existing Low/Target/High to new PercentageRange
                CswNbtView CompFixView = _CswNbtSchemaModTrnsctn.makeView();
                CompFixView.ViewName = "52299_compfixview";
                CswNbtViewRelationship rel1 = CompFixView.AddViewRelationship(ComponentOC, false);
                CompFixView.AddViewPropertyAndFilter(rel1, oldLowOCP, Conjunction: CswEnumNbtFilterConjunction.Or, FilterMode: CswEnumNbtFilterMode.NotNull);
                CompFixView.AddViewPropertyAndFilter(rel1, oldTargetOCP, Conjunction: CswEnumNbtFilterConjunction.Or, FilterMode: CswEnumNbtFilterMode.NotNull);
                CompFixView.AddViewPropertyAndFilter(rel1, oldHighOCP, Conjunction: CswEnumNbtFilterConjunction.Or, FilterMode: CswEnumNbtFilterMode.NotNull);

                ICswNbtTree CompFixTree = _CswNbtSchemaModTrnsctn.getTreeFromView(CompFixView, IncludeSystemNodes: true);
                while (CompFixTree.getChildNodeCount() > 0)
                {
                    for (Int32 c = 0; c < CompFixTree.getChildNodeCount(); c++)
                    {
                        CompFixTree.goToNthChild(c);

                        CswNbtObjClassMaterialComponent CompNode = CompFixTree.getCurrentNode();
                        CompNode.PercentageRange.Lower  = CompNode.Node.Properties[oldLowPercentageValue].AsNumber.Value;
                        CompNode.PercentageRange.Target = CompNode.Node.Properties[oldTargetPercentageValue].AsNumber.Value;
                        CompNode.PercentageRange.Upper  = CompNode.Node.Properties[oldHighPercentageValue].AsNumber.Value;
                        CompNode.PercentageRange.Units  = "%";

                        CompNode.Node.Properties[oldLowPercentageValue].AsNumber.Value    = Double.NaN;
                        CompNode.Node.Properties[oldTargetPercentageValue].AsNumber.Value = Double.NaN;
                        CompNode.Node.Properties[oldHighPercentageValue].AsNumber.Value   = Double.NaN;

                        CompNode.postChanges(false);

                        CompFixTree.goToParentNode();
                    } // for( Int32 c = 0; c < CompFixTree.getChildNodeCount(); c++ )

                    // next iteration
                    CompFixTree = _CswNbtSchemaModTrnsctn.getTreeFromView(CompFixView, IncludeSystemNodes: true);
                } // while( CompFixTree.getChildNodeCount() > 0 )


                // Delete existing Low/Target/High
                _CswNbtSchemaModTrnsctn.MetaData.DeleteObjectClassProp(oldLowOCP, true);
                _CswNbtSchemaModTrnsctn.MetaData.DeleteObjectClassProp(oldTargetOCP, true);
                _CswNbtSchemaModTrnsctn.MetaData.DeleteObjectClassProp(oldHighOCP, true);
                _CswNbtSchemaModTrnsctn.MetaData.DeleteObjectClassProp(oldPercentageOCP, true);
            }

            // Set default value of Units to %
            foreach (CswNbtMetaDataNodeType NodeType in ComponentOC.getNodeTypes())
            {
                CswNbtMetaDataNodeTypeProp PercentRangeNTP = NodeType.getNodeTypePropByObjectClassProp(CswNbtObjClassMaterialComponent.PropertyName.PercentageRange);
                PercentRangeNTP.DesignNode.AttributeProperty[CswNbtFieldTypeRuleNumericRange.AttributeName.DefaultValue].SetSubFieldValue(CswNbtFieldTypeRuleNumericRange.SubFieldName.Units, "%");
            }


            // Set layout on nodetypes
            CswNbtSchemaUpdateLayoutMgr AddLayoutMgr = new CswNbtSchemaUpdateLayoutMgr(_CswNbtSchemaModTrnsctn, CswEnumNbtObjectClass.MaterialComponentClass, LayoutType: CswEnumNbtLayoutType.Add);

            AddLayoutMgr.First.moveProp(Row: 1, Column: 1, PropName: CswNbtObjClassMaterialComponent.PropertyName.Mixture);
            AddLayoutMgr.First.moveProp(Row: 2, Column: 1, PropName: CswNbtObjClassMaterialComponent.PropertyName.Constituent);
            AddLayoutMgr.First.moveProp(Row: 3, Column: 1, PropName: CswNbtObjClassMaterialComponent.PropertyName.PercentageRange);
            AddLayoutMgr.First.moveProp(Row: 4, Column: 1, PropName: CswNbtObjClassMaterialComponent.PropertyName.Active);
            AddLayoutMgr.First.moveProp(Row: 5, Column: 1, PropName: CswNbtObjClassMaterialComponent.PropertyName.HazardousReporting);

            CswNbtSchemaUpdateLayoutMgr EditLayoutMgr = new CswNbtSchemaUpdateLayoutMgr(_CswNbtSchemaModTrnsctn, CswEnumNbtObjectClass.MaterialComponentClass, LayoutType: CswEnumNbtLayoutType.Edit);

            EditLayoutMgr.First.moveProp(Row: 1, Column: 1, PropName: CswNbtObjClassMaterialComponent.PropertyName.Mixture);
            EditLayoutMgr.First.moveProp(Row: 2, Column: 1, PropName: CswNbtObjClassMaterialComponent.PropertyName.Constituent);
            EditLayoutMgr.First.moveProp(Row: 3, Column: 1, PropName: CswNbtObjClassMaterialComponent.PropertyName.PercentageRange);
            EditLayoutMgr.First.moveProp(Row: 4, Column: 1, PropName: CswNbtObjClassMaterialComponent.PropertyName.Active);
            EditLayoutMgr.First.moveProp(Row: 5, Column: 1, PropName: CswNbtObjClassMaterialComponent.PropertyName.HazardousReporting);

            // Fix Chemical Components Grid
            CswNbtMetaDataNodeType ChemicalNT = _CswNbtSchemaModTrnsctn.MetaData.getNodeType("Chemical");

            if (null != ChemicalNT)
            {
                CswNbtMetaDataNodeTypeProp ComponentsNTP = ChemicalNT.getNodeTypeProp("Components");
                if (null != ComponentsNTP)
                {
                    CswNbtView         ComponentsView = _CswNbtSchemaModTrnsctn.restoreView(ComponentsNTP.ViewId);
                    CswNbtViewProperty percentageVP   = ComponentsView.findPropertyByName("Percentage");
                    if (null != percentageVP)
                    {
                        CswNbtMetaDataObjectClassProp PercentageRangeOCP = ComponentOC.getObjectClassProp(CswNbtObjClassMaterialComponent.PropertyName.PercentageRange);
                        percentageVP.Name = PercentageRangeOCP.PropName;
                        percentageVP.ObjectClassPropId = PercentageRangeOCP.ObjectClassPropId;
                        percentageVP.FieldType         = CswEnumNbtFieldType.NumericRange.ToString();
                        ComponentsView.save();
                    }

                    /*
                     *<TreeView viewname="Components" version="1.0" iconfilename="Images/view/viewgrid.gif" selectable="true" mode="Grid" width="100" viewid="3293" category="" visibility="Property"
                     *        visibilityroleid="" visibilityuserid="" groupbysiblings="false" included="true" isdemo="false" issystem="false" gridgroupbycol="">
                     *    <Relationship secondname="ChemicalClass" secondtype="ObjectClassId" secondid="147" secondiconfilename="atom.png" selectable="true" arbitraryid="root_OC_147" showintree="true"
                     *                  allowaddchildren="True" allowview="True" allowedit="True" allowdelete="True" nodeidstofilterin="" nodeidstofilterout="">
                     *        <Relationship propid="1373" propname="Mixture" proptype="ObjectClassPropId" propowner="Second" firstname="ChemicalClass" firsttype="ObjectClassId" firstid="147"
                     *                      secondname="MaterialComponentClass" secondtype="ObjectClassId" secondid="315" secondiconfilename="atom.png" selectable="true" arbitraryid="root_OC_147_OC_3151373"
                     *                      showintree="true" allowaddchildren="True" allowview="True" allowedit="True" allowdelete="True" nodeidstofilterin="" nodeidstofilterout="">
                     *            <Property type="ObjectClassPropId" nodetypepropid="-2147483648" objectclasspropid="1374" name="Constituent" arbitraryid="root_OC_147_OC_3151373_OCP_1374" sortby="False"
                     *                      sortmethod="Ascending" fieldtype="Relationship" order="1" width="" showingrid="True" />
                     *            <Property type="ObjectClassPropId" nodetypepropid="-2147483648" objectclasspropid="1364" name="Percentage" arbitraryid="root_OC_147_OC_3151373_OCP_1364" sortby="False"
                     *                      sortmethod="Ascending" fieldtype="Number" order="3" width="" showingrid="True" />
                     *            <Relationship propid="1374" propname="Constituent" proptype="ObjectClassPropId" propowner="First" firstname="MaterialComponentClass" firsttype="ObjectClassId"
                     *                      firstid="315" secondname="ChemicalClass" secondtype="ObjectClassId" secondid="147" secondiconfilename="atom.png" selectable="true"
                     *                      arbitraryid="root_OC_147_OC_3151373_OC_1471374" showintree="true" allowaddchildren="True" allowview="True" allowedit="True" allowdelete="True"
                     *                      nodeidstofilterin="" nodeidstofilterout="">
                     *                <Property type="NodeTypePropId" nodetypepropid="5583" objectclasspropid="-2147483648" name="CAS No" arbitraryid="root_OC_147_OC_3151373_OC_1471374_NTP_5583"
                     *                          sortby="False" sortmethod="Ascending" fieldtype="CASNo" order="2" width="" showingrid="True" />
                     *            </Relationship>
                     *        </Relationship>
                     *    </Relationship>
                     *</TreeView>
                     */
                }
            }
        }
Example #3
0
        public static void getCopyData(ICswResources _CswResources, CopyDataReturn Copy, CopyDataRequest Request)
        {
            CswNbtResources _CswNbtResources = (CswNbtResources)_CswResources;

            //If we get any more copy types in the future, extract them out into their own classes and instantiate them via factory
            #region Create_Material Copy Data

            if (Request.CopyType == CswEnumNbtActionName.Create_Material)
            {
                CswPrimaryKey OriginalNodeId = CswConvert.ToPrimaryKey(Request.NodeId);
                if (CswTools.IsPrimaryKey(OriginalNodeId))
                {
                    CswNbtPropertySetMaterial OriginalMaterial = _CswNbtResources.Nodes.GetNode(OriginalNodeId);
                    if (null != OriginalMaterial)
                    {
                        #region Material Properties

                        CswNbtPropertySetMaterial MaterialCopy = OriginalMaterial.CopyNode();
                        Copy.Data.Create_Material = new C3CreateMaterialResponse
                        {
                            actionname = CswEnumNbtActionName.Create_Material,
                            state      = new C3CreateMaterialResponse.State
                            {
                                materialId   = MaterialCopy.NodeId.ToString(),
                                materialType = new C3CreateMaterialResponse.State.MaterialType
                                {
                                    name = MaterialCopy.NodeType.NodeTypeName,
                                    val  = CswConvert.ToInt32(MaterialCopy.NodeTypeId)
                                },
                                tradeName = OriginalMaterial.TradeName.Text,
                                partNo    = OriginalMaterial.PartNumber.Text,
                                supplier  = new C3CreateMaterialResponse.State.Supplier
                                {
                                    name = OriginalMaterial.Supplier.CachedNodeName,
                                    val  = OriginalMaterial.Supplier.RelatedNodeId.ToString()
                                },
                                sizes           = new Collection <C3CreateMaterialResponse.State.SizeRecord>(),
                                showOriginalUoM = false
                            }
                        };

                        #endregion Material Properties

                        #region Sizes

                        CswNbtMetaDataObjectClass     SizeOC      = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.SizeClass);
                        CswNbtMetaDataObjectClassProp MaterialOCP = SizeOC.getObjectClassProp(CswNbtObjClassSize.PropertyName.Material);
                        CswNbtView SizesView = new CswNbtView(_CswNbtResources)
                        {
                            ViewName = "MaterialCopySizes"
                        };
                        CswNbtViewRelationship SizeVR = SizesView.AddViewRelationship(SizeOC, false);
                        SizesView.AddViewPropertyAndFilter(SizeVR, MaterialOCP, OriginalMaterial.NodeId.PrimaryKey.ToString(), CswEnumNbtSubFieldName.NodeID);
                        ICswNbtTree SizesTree = _CswNbtResources.Trees.getTreeFromView(SizesView, false, false, false);
                        for (int i = 0; i < SizesTree.getChildNodeCount(); i++)
                        {
                            SizesTree.goToNthChild(i);
                            CswNbtObjClassSize SizeNode = SizesTree.getNodeForCurrentPosition();
                            Copy.Data.Create_Material.state.sizes.Add(new C3CreateMaterialResponse.State.SizeRecord
                            {
                                nodeTypeId = new C3CreateMaterialResponse.State.SizeRecord.SizeData
                                {
                                    value    = SizeNode.NodeTypeId.ToString(),
                                    readOnly = true,
                                    hidden   = true
                                },
                                unitCount = new C3CreateMaterialResponse.State.SizeRecord.SizeData
                                {
                                    value    = CswConvert.ToString(SizeNode.UnitCount.Value),
                                    readOnly = true,
                                    hidden   = false
                                },
                                quantity = new C3CreateMaterialResponse.State.SizeRecord.SizeData
                                {
                                    value    = CswConvert.ToString(SizeNode.InitialQuantity.Quantity),
                                    readOnly = true,
                                    hidden   = false
                                },
                                uom = new C3CreateMaterialResponse.State.SizeRecord.SizeData
                                {
                                    value    = SizeNode.InitialQuantity.CachedUnitName,
                                    readOnly = false == string.IsNullOrEmpty(SizeNode.InitialQuantity.CachedUnitName),
                                    hidden   = false,
                                    id       = SizeNode.InitialQuantity.UnitId.ToString()
                                },
                                catalogNo = new C3CreateMaterialResponse.State.SizeRecord.SizeData
                                {
                                    value    = SizeNode.CatalogNo.Text,
                                    readOnly = true,
                                    hidden   = false
                                },
                                quantityEditable = new C3CreateMaterialResponse.State.SizeRecord.SizeData
                                {
                                    value = SizeNode.QuantityEditable.Checked,
                                },
                                dispensible = new C3CreateMaterialResponse.State.SizeRecord.SizeData
                                {
                                    value = SizeNode.Dispensable.Checked
                                }
                            });
                            SizesTree.goToParentNode();
                        }

                        #endregion Sizes

                        #region Synonyms

                        CswNbtMetaDataObjectClass     MaterialSynonymOC = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.MaterialSynonymClass);
                        CswNbtMetaDataObjectClassProp SynMaterialOCP    = MaterialSynonymOC.getObjectClassProp(CswNbtObjClassMaterialSynonym.PropertyName.Material);
                        CswNbtView SynonymsView = new CswNbtView(_CswNbtResources)
                        {
                            ViewName = "MaterialCopySynonyms"
                        };
                        CswNbtViewRelationship SynonymsVR = SynonymsView.AddViewRelationship(MaterialSynonymOC, false);
                        SynonymsView.AddViewPropertyAndFilter(SynonymsVR, SynMaterialOCP, OriginalMaterial.NodeId.PrimaryKey.ToString(), CswEnumNbtSubFieldName.NodeID);
                        ICswNbtTree SynonymsTree = _CswNbtResources.Trees.getTreeFromView(SynonymsView, false, false, false);
                        for (int i = 0; i < SynonymsTree.getChildNodeCount(); i++)
                        {
                            SynonymsTree.goToNthChild(i);
                            CswNbtObjClassMaterialSynonym SynonymNode = SynonymsTree.getNodeForCurrentPosition();
                            CswNbtObjClassMaterialSynonym SynonymCopy = SynonymNode.CopyNode();
                            SynonymCopy.Material.RelatedNodeId = MaterialCopy.NodeId;
                            SynonymCopy.postChanges(false);
                            SynonymsTree.goToParentNode();
                        }

                        #endregion Synonyms

                        if (MaterialCopy.ObjectClass.ObjectClass == CswEnumNbtObjectClass.ChemicalClass)
                        {
                            if (CswEnumTristate.False == MaterialCopy.IsConstituent.Checked)
                            {
                                #region SDS

                                CswNbtView  SDSView = CswNbtObjClassSDSDocument.getAssignedSDSDocumentsView(_CswNbtResources, OriginalMaterial.NodeId);
                                ICswNbtTree SDSTree = _CswNbtResources.Trees.getTreeFromView(SDSView, false, false, false);
                                SDSTree.goToNthChild(0);
                                for (int i = 0; i < SDSTree.getChildNodeCount(); i++)
                                {
                                    SDSTree.goToNthChild(i);
                                    CswNbtObjClassSDSDocument SDSDoc  = SDSTree.getNodeForCurrentPosition();
                                    CswNbtObjClassSDSDocument SDSCopy = SDSDoc.CopyNode(IsNodeTemp: true);

                                    SDSCopy.Owner.RelatedNodeId = MaterialCopy.NodeId;
                                    SDSCopy.postChanges(false);

                                    if (i == 0)
                                    {
                                        Copy.Data.Create_Material.state.sds.sdsDocId = SDSCopy.NodeId.ToString();
                                    }
                                    SDSTree.goToParentNode();
                                }

                                #endregion SDS

                                #region Components

                                CswNbtMetaDataObjectClass     MaterialComponentOC = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.MaterialComponentClass);
                                CswNbtMetaDataObjectClassProp CompMaterialOCP     = MaterialComponentOC.getObjectClassProp(CswNbtObjClassMaterialComponent.PropertyName.Mixture);
                                CswNbtView ComponentsView = new CswNbtView(_CswNbtResources)
                                {
                                    ViewName = "MaterialCopyComponents"
                                };
                                CswNbtViewRelationship ComponentsVR = ComponentsView.AddViewRelationship(MaterialComponentOC, false);
                                ComponentsView.AddViewPropertyAndFilter(ComponentsVR, CompMaterialOCP, OriginalMaterial.NodeId.PrimaryKey.ToString(), CswEnumNbtSubFieldName.NodeID);
                                ICswNbtTree ComponentsTree = _CswNbtResources.Trees.getTreeFromView(ComponentsView, false, false, false);
                                for (int i = 0; i < ComponentsTree.getChildNodeCount(); i++)
                                {
                                    ComponentsTree.goToNthChild(i);
                                    CswNbtObjClassMaterialComponent ComponentNode = ComponentsTree.getNodeForCurrentPosition();
                                    CswNbtObjClassMaterialComponent ComponentCopy = ComponentNode.CopyNode();
                                    ComponentCopy.Mixture.RelatedNodeId     = MaterialCopy.NodeId;
                                    ComponentCopy.Constituent.RelatedNodeId = ComponentNode.Constituent.RelatedNodeId;
                                    ComponentCopy.postChanges(false);
                                    ComponentsTree.goToParentNode();
                                }

                                #endregion Components
                            }

                            #region GHS

                            CswNbtMetaDataObjectClass     GHSOC          = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.GHSClass);
                            CswNbtMetaDataObjectClassProp GHSMaterialOCP = GHSOC.getObjectClassProp(CswNbtObjClassGHS.PropertyName.Material);
                            CswNbtView GHSView = new CswNbtView(_CswNbtResources)
                            {
                                ViewName = "MaterialCopyGHS"
                            };
                            CswNbtViewRelationship GHSVR = GHSView.AddViewRelationship(GHSOC, false);
                            GHSView.AddViewPropertyAndFilter(GHSVR, GHSMaterialOCP, OriginalMaterial.NodeId.PrimaryKey.ToString(), CswEnumNbtSubFieldName.NodeID);
                            ICswNbtTree GHSTree = _CswNbtResources.Trees.getTreeFromView(GHSView, false, false, false);
                            for (int i = 0; i < GHSTree.getChildNodeCount(); i++)
                            {
                                GHSTree.goToNthChild(i);
                                CswNbtObjClassGHS GHSNode = GHSTree.getNodeForCurrentPosition();
                                CswNbtObjClassGHS GHSCopy = GHSNode.CopyNode();
                                GHSCopy.Material.RelatedNodeId = MaterialCopy.NodeId;
                                GHSCopy.postChanges(false);
                                GHSTree.goToParentNode();
                            }

                            #endregion GHS
                        }
                    }
                }
            }

            #endregion Create_Material Copy Data
        }