예제 #1
0
        private bool _updateNodeProps(JObject NodeObj)
        {
            bool Ret = false;
            Collection <JProperty> Props = new Collection <JProperty>();


            if (null != NodeObj.Property("tabs"))
            {
                JObject Tabs = (JObject)NodeObj.Property("tabs").Value;
                foreach (JProperty Prop in from Tab
                         in Tabs.Properties()
                         where (null != Tab.Value)
                         select(JObject) Tab.Value
                         into TabProps
                         from Prop
                         in TabProps.Properties()
                         where (null != Prop.Value &&
                                Prop.Name != "nexttab" &&
                                Prop.Name != "currenttab")
                         let PropAtr = (JObject)Prop.Value
                                       where null != PropAtr["wasmodified"] &&
                                       CswConvert.ToBoolean(PropAtr["wasmodified"])
                                       select Prop)
                {
                    Props.Add(Prop);
                }
            }


            // post changes once per node, not once per prop
            Collection <CswNbtNode> NodesToPost = new Collection <CswNbtNode>();

            foreach (JProperty Prop in Props)
            {
                if (null != Prop.Name)
                {
                    string        NodePropId      = Prop.Name; // ~ "prop_4019_nodeid_nodes_24709"
                    string[]      SplitNodePropId = NodePropId.Split('_');
                    Int32         NodeTypePropId  = CswConvert.ToInt32(SplitNodePropId[1]);
                    CswPrimaryKey NodePk          = new CswPrimaryKey(SplitNodePropId[3], CswConvert.ToInt32(SplitNodePropId[4]));

                    CswNbtNode Node = _CswNbtResources.Nodes[NodePk];
                    CswNbtMetaDataNodeTypeProp MetaDataProp = _CswNbtResources.MetaData.getNodeTypeProp(NodeTypePropId);

                    JObject PropObj = (JObject)Prop.Value;

                    CswNbtMetaDataNodeTypeTab Tab = _CswNbtResources.MetaData.getNodeTypeTab(Node.NodeTypeId, CswConvert.ToString(PropObj["currenttab"]));
                    Node.Properties[MetaDataProp].ReadJSON(PropObj, null, null);

                    //Case 20964. Client needs to know whether the inspection is complete.
                    if (false == Ret && Node.getObjectClass().ObjectClass == CswNbtMetaDataObjectClass.NbtObjectClass.InspectionDesignClass)
                    {
                        CswNbtMetaDataObjectClassProp MetaDataOCP = MetaDataProp.getObjectClassProp();
                        if (MetaDataOCP != null)
                        {
                            CswNbtMetaDataObjectClassProp Finish = _CswNbtResources.MetaData.getObjectClassProp(Node.getObjectClassId(), CswNbtObjClassInspectionDesign.PropertyName.Finish);
                            CswNbtMetaDataObjectClassProp Cancel = _CswNbtResources.MetaData.getObjectClassProp(Node.getObjectClassId(), CswNbtObjClassInspectionDesign.PropertyName.Cancel);
                            if (MetaDataOCP == Finish ||
                                MetaDataOCP == Cancel)
                            {
                                //Ret = Ret || Node.Properties[MetaDataProp].AsButton.Checked == Tristate.True;
                                CswNbtObjClass.NbtButtonData ButtonData = new CswNbtObjClass.NbtButtonData(MetaDataProp);
                                ((CswNbtObjClassInspectionDesign)Node).onButtonClick(ButtonData);
                            }
                        }
                    }

                    if (false == NodesToPost.Contains(Node))
                    {
                        NodesToPost.Add(Node);
                    }
                }
            }

            foreach (CswNbtNode Node in NodesToPost)
            {
                Node.postChanges(false);
            }
            return(Ret);
        }
        public string RecalculateReferenceValue()
        {
            string Value = String.Empty;

            if (RelationshipId > 0 && RelatedPropId > 0)
            {
                CswNbtMetaDataNodeTypeProp RelationshipNTP = _getRelationshipProp();
                if (null != RelationshipNTP)
                {
                    CswPrimaryKey RelatedNodeId = _Node.Properties[RelationshipNTP].AsRelationship.RelatedNodeId;
                    CswNbtNode    RelatedNode   = _CswNbtResources.Nodes[RelatedNodeId];
                    if (null != RelatedNode)
                    {
                        CswNbtMetaDataNodeTypeProp ToReferenceNtp = null;

                        // CIS-52280 - This is a bit of a kludge.
                        // If the relationship is by property set (e.g. Container's Material),
                        // but the property reference is defined by object class, then the valuepropid will be wrong.
                        // We have to look it up by object class property name instead.
                        // See CIS-50822 for a more permanent fix.
                        if (RelationshipNTP.FKType == CswEnumNbtViewRelatedIdType.PropertySetId.ToString())
                        {
                            if (RelatedPropType == CswEnumNbtViewPropIdType.NodeTypePropId)
                            {
                                CswNbtMetaDataNodeTypeProp origRefProp = _CswNbtResources.MetaData.getNodeTypeProp(RelatedPropId);
                                if (null != origRefProp.getObjectClassProp())
                                {
                                    ToReferenceNtp = RelatedNode.getNodeType().getNodeTypePropByObjectClassProp(origRefProp.getObjectClassProp().PropName);
                                }
                                else
                                {
                                    ToReferenceNtp = RelatedNode.getNodeType().getNodeTypeProp(origRefProp.PropName);
                                }
                            }
                            else if (RelatedPropType == CswEnumNbtViewPropIdType.ObjectClassPropId)
                            {
                                CswNbtMetaDataObjectClassProp origRefProp = _CswNbtResources.MetaData.getObjectClassProp(RelatedPropId);
                                ToReferenceNtp = RelatedNode.getNodeType().getNodeTypePropByObjectClassProp(origRefProp.PropName);
                            }
                        }
                        else if (RelatedPropType == CswEnumNbtViewPropIdType.NodeTypePropId)
                        {
                            ToReferenceNtp = _CswNbtResources.MetaData.getNodeTypeProp(RelatedPropId);
                        }
                        else if (RelatedPropType == CswEnumNbtViewPropIdType.ObjectClassPropId)
                        {
                            ToReferenceNtp = RelatedNode.getNodeType().getNodeTypePropByObjectClassProp(RelatedPropId);
                        }

                        if (null != ToReferenceNtp)
                        {
                            Value = RelatedNode.Properties[ToReferenceNtp].Gestalt;
                        }
                    }
                }
            } // if (RelationshipId > 0 && RelatedPropId > 0)

            SetPropRowValue(_CachedValueSubField, Value);
            _setGestalt(Value, Sequence);
            PendingUpdate = false;

            return(Value);
        }
        } // getLayout()

        /// <summary>
        /// Updates the given layout by placing the given property in the specified locaiton (or at the bottom)
        /// </summary>
        /// <param name="LayoutType">Add, Edit, Preview, or Table (Search)</param>
        /// <param name="NodeTypeId">NodetypeId of the NodeType to which the prop belongs</param>
        /// <param name="NtProp">Prop to move</param>
        /// <param name="DoMove">If true, remove the prop from other tab(s) before moving to the new one (Edit Layout only)</param>
        /// <param name="TabId">TabId to which the prop should be added (Edit Layout Only)</param>
        /// <param name="DisplayRow">Row number to place the property.  If the cell is taken, it will be placed beneath the pre-existing prop</param>
        /// <param name="DisplayColumn">Column number to place the property.  If the cell is taken, it will be placed beneath the pre-existing prop</param>
        /// <param name="TabGroup">(Optional) specify the name of the TabGroup with which to place the prop (if it doesn't exist, one will be created)</param>
        public void updatePropLayout(CswEnumNbtLayoutType LayoutType, Int32 NodeTypeId, CswNbtMetaDataNodeTypeProp NtProp, bool DoMove, Int32 TabId = Int32.MinValue, Int32 DisplayRow = Int32.MinValue, Int32 DisplayColumn = Int32.MinValue, string TabGroup = "")
        {
            if (LayoutType != CswEnumNbtLayoutType.Unknown &&
                null != NtProp)
            {
                if (DoMove)
                {
                    removePropFromLayout(LayoutType, NtProp, Int32.MinValue);
                }
                CswTableUpdate LayoutUpdate = _CswNbtMetaDataResources.CswNbtResources.makeCswTableUpdate("updatePropLayout_Update", "nodetype_layout");
                string         WhereClause  = "where layouttype = '" + LayoutType.ToString() + "' and nodetypepropid = " + NtProp.PropId.ToString();
                if (TabId != Int32.MinValue && LayoutType == CswEnumNbtLayoutType.Edit)
                {
                    WhereClause += " and nodetypetabsetid = " + TabId.ToString();
                }
                DataTable LayoutTable = LayoutUpdate.getTable(WhereClause);

                DataRow Row = null;
                if (LayoutTable.Rows.Count > 0)
                {
                    Row = LayoutTable.Rows[0];
                }
                else
                {
                    Row = LayoutTable.NewRow();
                    LayoutTable.Rows.Add(Row);
                }
                Row["layouttype"]     = LayoutType.ToString();
                Row["nodetypeid"]     = CswConvert.ToDbVal(NodeTypeId);
                Row["nodetypepropid"] = CswConvert.ToDbVal(NtProp.PropId);
                Row["auditlevel"]     = NtProp.AuditLevel.ToString(); // layout audit goes with property audit

                if (LayoutType == CswEnumNbtLayoutType.Edit)
                {
                    if (TabId != Int32.MinValue)
                    {
                        Row["nodetypetabsetid"] = CswConvert.ToDbVal(TabId);
                    }
                    else
                    {
                        throw new CswDniException(CswEnumErrorType.Error, "Tab is required", "CswNbtMetaDataNodeTypeLayoutMgr.updatePropLayout() requires a valid TabId for Edit layouts");
                    }
                }

                Int32 FinalDisplayRow = DisplayRow;
                Int32 FinalDisplayCol = DisplayColumn;

                //Very special case for 'Save'--it is always last
                if (FinalDisplayRow == Int32.MaxValue)
                {
                    CswNbtMetaDataObjectClassProp Ocp = NtProp.getObjectClassProp();
                    if (null == Ocp || Ocp.PropName != CswNbtObjClass.PropertyName.Save)
                    {
                        FinalDisplayRow = Int32.MaxValue - 1;
                    }
                }
                else
                {
                    if (FinalDisplayRow <= 0)
                    {
                        FinalDisplayRow = getCurrentMaxDisplayRow(NodeTypeId, TabId, LayoutType) + 1;
                    }
                    if (FinalDisplayCol <= 0)
                    {
                        FinalDisplayCol = 1;
                    }
                }
                Row["display_row"]    = CswConvert.ToDbVal(FinalDisplayRow);
                Row["display_column"] = CswConvert.ToDbVal(FinalDisplayCol);

                Row["tabgroup"] = TabGroup;

                LayoutUpdate.update(LayoutTable);
            } // if( Type != CswEnumNbtLayoutType.Unknown && Prop != null )

            if (_Cache.ContainsKey(NodeTypeId))
            {
                _Cache.Remove(NodeTypeId);
            }
        } // updatePropLayout()