}//afterWriteNode()

        private void _updateEquipment()
        {
            // For each equipment related to this assembly, mark matching properties as pending update
            if (CswEnumNbtNodeModificationState.Modified == _CswNbtNode.ModificationState)
            {
                CswStaticSelect PropRefsSelect = _CswNbtResources.makeCswStaticSelect("afterWriteNode_select", "getMatchingEquipPropsForAssembly");
                CswStaticParam  StaticParam    = new CswStaticParam("getassemblynodeid", _CswNbtNode.NodeId.PrimaryKey);
                PropRefsSelect.S4Parameters.Add("getassemblynodeid", StaticParam);
                DataTable PropRefsTable = PropRefsSelect.getTable();

                // Update the nodes.pendingupdate directly, to avoid having to fetch all the node info for every related node
                string PkString = String.Empty;
                foreach (DataRow PropRefsRow in PropRefsTable.Rows)
                {
                    if (PkString != String.Empty)
                    {
                        PkString += ",";
                    }
                    PkString += PropRefsRow["nodeid"].ToString();
                }
                if (PkString != String.Empty)
                {
                    CswTableUpdate NodesUpdate = _CswNbtResources.makeCswTableUpdate("afterWriteNode_update", "nodes");
                    DataTable      NodesTable  = NodesUpdate.getTable("where nodeid in (" + PkString + ")");
                    foreach (DataRow NodesRow in NodesTable.Rows)
                    {
                        NodesRow["pendingupdate"] = "1";
                    }
                    NodesUpdate.update(NodesTable);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        public CswNbtActionCollection(CswNbtResources Resources, bool ExcludeDisabledActions)
        {
            _CswNbtResources = Resources;

            _ActionSL   = new SortedList();
            _ActionHash = new Hashtable();

            // Actions
            DataTable ActionsTable = null;

            if (ExcludeDisabledActions)
            {
                CswStaticSelect ActionsSelect = _CswNbtResources.makeCswStaticSelect("CswNbtActionCollection.ActionsSelect", "getActiveActions");
                ActionsTable = ActionsSelect.getTable();
            }
            else
            {
                CswTableSelect ActionsSelect = _CswNbtResources.makeCswTableSelect("CswNbtActionCollection.AllActionsSelect", "actions");
                ActionsTable = ActionsSelect.getTable();
            }

            foreach (DataRow ActionRow in ActionsTable.Rows)
            {
                try
                {
                    CswEnumNbtActionName CurrentActionName = CswNbtAction.ActionNameStringToEnum(ActionRow["actionname"].ToString());
                    if (CurrentActionName != CswResources.UnknownEnum)
                    {
                        Int32        ActionId = CswConvert.ToInt32(ActionRow["actionid"]);
                        CswNbtAction Action   = new CswNbtAction(_CswNbtResources,
                                                                 ActionId,
                                                                 ActionRow["url"].ToString(),
                                                                 CurrentActionName,
                                                                 CswConvert.ToBoolean(ActionRow["showinlist"]),
                                                                 ActionRow["category"].ToString(),
                                                                 CswConvert.ToString(ActionRow["iconfilename"]));
                        string ActionNameAsString = CswNbtAction.ActionNameEnumToString(CurrentActionName);
                        if (false == _ActionSL.ContainsKey(ActionNameAsString))
                        {
                            _ActionSL.Add(ActionNameAsString, Action);
                        }
                        if (false == _ActionHash.ContainsKey(ActionId))
                        {
                            _ActionHash.Add(ActionId, Action);
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Log the error but keep going
                    _CswNbtResources.logError(new CswDniException(CswEnumErrorType.Error, "System Error", "Encountered an invalid Action: " + ActionRow["actionname"] + " (" + ActionRow["actionid"] + ")", ex));
                }
            }
        }
        /// <summary>
        /// Get all views with visibility set to the current user
        /// </summary>
        public DataTable getUserViews(out Dictionary <CswNbtViewId, CswNbtView> AllEnabledViews)
        {
            DataTable Ret = null;
            Dictionary <CswNbtViewId, CswNbtView> OutEnabledViews = new Dictionary <CswNbtViewId, CswNbtView>();
            CswStaticSelect ViewsSelect = _CswNbtResources.makeCswStaticSelect("getUserViews_select", "getUserViewInfo");

            ViewsSelect.S4Parameters.Add("getuserid", new CswStaticParam("getuserid", _CswNbtResources.CurrentUser.UserId.PrimaryKey.ToString()));
            Ret = ViewsSelect.getTable();

            foreach (DataRow Row in Ret.Rows)
            {
                CswNbtViewId ThisViewId = new CswNbtViewId(CswConvert.ToInt32(Row["nodeviewid"]));
                CswNbtView   ThisView   = restoreView(ThisViewId);
                OutEnabledViews.Add(ThisView.ViewId, ThisView);
            }
            AllEnabledViews = OutEnabledViews;

            return(Ret);
        }
        /// <summary>
        /// Get a DataTable of all enabled views in the database
        /// </summary>
        public DataTable getAllEnabledViews(out Dictionary <CswNbtViewId, CswNbtView> AllEnabledViews)
        {
            CswStaticSelect ViewsSelect = _CswNbtResources.makeCswStaticSelect("CswNbtViewSelect.getAllViews_select", "getAllViewInfo");
            Dictionary <CswNbtViewId, CswNbtView> OutEnabledViews = new Dictionary <CswNbtViewId, CswNbtView>();
            CswNbtNode ChemSwAdminUser = _CswNbtResources.Nodes.makeUserNodeFromUsername(CswNbtObjClassUser.ChemSWAdminUsername);
            CswNbtNode ChemSwAdminRole = _CswNbtResources.Nodes.makeRoleNodeFromRoleName(CswNbtObjClassRole.ChemSWAdminRoleName);
            bool       ExcludeCswAdmin = (_CswNbtResources.CurrentNbtUser.Username != CswNbtObjClassUser.ChemSWAdminUsername ||
                                          _CswNbtResources.CurrentNbtUser.Rolename != CswNbtObjClassRole.ChemSWAdminRoleName);

            DataTable            AllViews   = ViewsSelect.getTable();
            Collection <DataRow> DoomedRows = new Collection <DataRow>();

            foreach (DataRow Row in AllViews.Rows)
            {
                CswNbtViewId ViewId = new CswNbtViewId(CswConvert.ToInt32(Row["nodeviewid"]));
                CswNbtView   View   = _CswNbtResources.ViewSelect.restoreView(ViewId);
                if (false == View.IsFullyEnabled() ||
                    (_CswNbtResources.CurrentNbtUser.Username != CswNbtObjClassUser.ChemSWAdminUsername && CswConvert.ToBoolean(Row["issystem"])) ||
                    (ExcludeCswAdmin &&
                     ((View.Visibility == CswEnumNbtViewVisibility.Role &&
                       View.VisibilityRoleId == ChemSwAdminRole.NodeId) ||
                      (View.Visibility == CswEnumNbtViewVisibility.User &&
                       View.VisibilityUserId == ChemSwAdminUser.NodeId))))
                {
                    DoomedRows.Add(Row);
                }
                else
                {
                    OutEnabledViews.Add(ViewId, View);
                }
            }
            foreach (DataRow DoomedRow in DoomedRows)
            {
                DoomedRow.Delete();
            }
            AllEnabledViews = OutEnabledViews;
            AllViews.AcceptChanges();
            return(AllViews);
        }
        }//ctor

        private Collection <CswNbtNode> _getRawNodes(CswEnumNbtScheduleRuleNames NbtScheduleRuleName)
        {
            Collection <CswNbtNode> ReturnVal = new Collection <CswNbtNode>();

            CswStaticSelect CswTableSelect = _CswNbtResources.makeCswStaticSelect("query for s4: " + NbtScheduleRuleName.ToString(), NbtScheduleRuleName.ToString());
            DataTable       DataTable      = CswTableSelect.getTable();

            foreach (DataRow CurrentRow in DataTable.Rows)
            {
                Int32 NodeId = CswConvert.ToInt32(CurrentRow["nodeid"]);
                if (Int32.MinValue != NodeId)
                {
                    CswPrimaryKey NodePk     = new CswPrimaryKey("nodes", NodeId);
                    CswNbtNode    CswNbtNode = _CswNbtResources.Nodes.GetNode(NodePk);
                    if (null != CswNbtNode)
                    {
                        ReturnVal.Add(CswNbtNode);
                    }
                }
            }

            return(ReturnVal);
        }//getRawNodes()
        private Collection <CswNbtViewRelationship> getPropertySetRelated(Int32 PropertySetId, CswNbtView View, Int32 Level)
        {
            Collection <CswNbtViewRelationship> Relationships = new Collection <CswNbtViewRelationship>();

            // If we're doing a grid, we can only pick things in which the provided nodetype has a relationship to,
            // rather than things that are related to the provided nodetype.
            // If this is a property grid, then the above rule does not apply to the first level.
            bool Restrict = (View.ViewMode == CswEnumNbtViewRenderingMode.Grid || View.ViewMode == CswEnumNbtViewRenderingMode.Table) &&
                            (View.Visibility != CswEnumNbtViewVisibility.Property || Level >= 2);

            CswNbtMetaDataPropertySet PropertySet = _CswNbtResources.MetaData.getPropertySet(PropertySetId);

            CswStaticSelect RelationshipPropsSelect = _CswNbtResources.makeCswStaticSelect("getRelationsForPropertySetId_select", "getRelationsForPropertySetId");

            RelationshipPropsSelect.S4Parameters.Add("getpropertysetid", new CswStaticParam("getpropertysetid", PropertySetId));
            DataTable RelationshipPropsTable = RelationshipPropsSelect.getTable();

            foreach (DataRow PropRow in RelationshipPropsTable.Rows)
            {
                // Ignore relationships that don't have a target
                if (PropRow["fktype"].ToString() != String.Empty &&
                    PropRow["fkvalue"].ToString() != String.Empty)
                {
                    ICswNbtMetaDataProp ThisProp = null;
                    if (PropRow["proptype"].ToString() == CswEnumNbtViewPropIdType.ObjectClassPropId.ToString())
                    {
                        ThisProp = _CswNbtResources.MetaData.getObjectClassProp(CswConvert.ToInt32(PropRow["propid"]));
                    }
                    else if (PropRow["proptype"].ToString() == CswEnumNbtViewPropIdType.NodeTypePropId.ToString())
                    {
                        ThisProp = _CswNbtResources.MetaData.getNodeTypeProp(CswConvert.ToInt32(PropRow["propid"]));
                    }

                    if (PropRow["propertysetid"].ToString() == CswEnumNbtViewRelatedIdType.PropertySetId.ToString() &&
                        PropRow["fktype"].ToString() == CswEnumNbtViewRelatedIdType.PropertySetId.ToString() &&
                        PropRow["fkvalue"].ToString() == PropertySetId.ToString())
                    {
                        // Special case -- relationship to my own set
                        // We need to create two relationships from this
                        CswNbtViewRelationship R1 = View.AddViewRelationship(null, CswEnumNbtViewPropOwnerType.First, ThisProp, false);
                        R1.overrideFirst(PropertySet);
                        R1.overrideSecond(PropertySet);
                        _InsertRelationship(Relationships, R1);

                        if (!Restrict)
                        {
                            CswNbtViewRelationship R2 = View.AddViewRelationship(null, CswEnumNbtViewPropOwnerType.Second, ThisProp, false);
                            R2.overrideFirst(PropertySet);
                            R2.overrideSecond(PropertySet);
                            _InsertRelationship(Relationships, R2);
                        }
                    }
                    else
                    {
                        CswNbtViewRelationship R = null;
                        if (PropRow["propertysetid"].ToString() == PropertySetId.ToString())
                        {
                            // my relation to something else
                            R = View.AddViewRelationship(null, CswEnumNbtViewPropOwnerType.First, ThisProp, false);
                            R.overrideSecond(PropRow["fktype"].ToString(), CswConvert.ToInt32(PropRow["fkvalue"]));
                            R.overrideFirst(PropertySet);
                            _InsertRelationship(Relationships, R);
                        }
                        else if (PropRow["fktype"].ToString() == CswEnumNbtViewRelatedIdType.PropertySetId.ToString() &&
                                 PropRow["fkvalue"].ToString() == PropertySetId.ToString())
                        {
                            if (!Restrict)
                            {
                                // something else's relation to me
                                R = View.AddViewRelationship(null, CswEnumNbtViewPropOwnerType.Second, ThisProp, false);
                                if (PropRow["proptype"].ToString() == CswEnumNbtViewPropIdType.ObjectClassPropId.ToString())
                                {
                                    R.overrideSecond(_CswNbtResources.MetaData.getObjectClass(CswConvert.ToInt32(PropRow["typeid"])));
                                }
                                else
                                {
                                    R.overrideSecond(_CswNbtResources.MetaData.getNodeType(CswConvert.ToInt32(PropRow["typeid"])));
                                }
                                R.overrideFirst(PropertySet);
                                _InsertRelationship(Relationships, R);
                            }
                        }
                        else
                        {
                            throw new CswDniException(CswEnumErrorType.Error, "An unexpected data condition has occurred", "getPropertySetRelated() found a relationship which did not match the original propertysetid");
                        }
                    }
                }
            }

            return(Relationships);
        }
        /// <summary>
        /// Get a Collection of all views visible to the current user, and the DataTable
        /// </summary>
        public Dictionary <CswNbtViewId, CswNbtView> getVisibleViews(string OrderBy, ICswNbtUser User, bool IncludeEmptyViews, bool MobileOnly, bool SearchableOnly, CswEnumNbtViewRenderingMode ViewRenderingMode, out DataTable ViewsTable, CswCommaDelimitedString LimitToViews = null, bool ForEdit = false)
        {
            CswTimer VisibleViewsTimer = new CswTimer();

            ViewsTable = null;

            Dictionary <CswNbtViewId, CswNbtView> Ret = new Dictionary <CswNbtViewId, CswNbtView>();

            if (null != User && CswTools.IsPrimaryKey(User.UserId) && CswTools.IsPrimaryKey(User.RoleId))
            {
                if (null == LimitToViews || LimitToViews.Count > 0)
                {
                    CswStaticSelect ViewsSelect = _CswNbtResources.makeCswStaticSelect("getVisibleViews_select", "getVisibleViewInfo");
                    ViewsSelect.S4Parameters.Add("getroleid", new CswStaticParam("getroleid", User.RoleId.PrimaryKey.ToString()));
                    ViewsSelect.S4Parameters.Add("getuserid", new CswStaticParam("getuserid", User.UserId.PrimaryKey.ToString()));
                    string AddClause = " ";
                    if (MobileOnly)
                    {
                        AddClause += "and formobile = '" + CswConvert.ToDbVal(true) + "'";
                    }
                    if (ViewRenderingMode != CswEnumNbtViewRenderingMode.Any)
                    {
                        AddClause += "and viewmode = '" + ViewRenderingMode.ToString() + "'";
                    }
                    if (null != LimitToViews)
                    {
                        AddClause += "and nodeviewid in (" + LimitToViews.ToString() + ")";
                    }
                    ViewsSelect.S4Parameters.Add("addclause", new CswStaticParam("addclause", AddClause, true));
                    if (OrderBy != string.Empty)
                    {
                        ViewsSelect.S4Parameters.Add("orderbyclause", new CswStaticParam("orderbyclause", OrderBy));
                    }
                    else
                    {
                        ViewsSelect.S4Parameters.Add("orderbyclause", new CswStaticParam("orderbyclause", "lower(v.viewname)"));
                    }
                    ViewsTable = ViewsSelect.getTable();

                    _CswNbtResources.logTimerResult("CswNbtView.getVisibleViews() data fetched", VisibleViewsTimer.ElapsedDurationInSecondsAsString);

                    Collection <DataRow> RowsToRemove = new Collection <DataRow>();
                    foreach (DataRow Row in ViewsTable.Rows)
                    {
                        CswNbtView ThisView = new CswNbtView(_CswNbtResources);
                        ThisView.LoadXml(Row["viewxml"].ToString());

                        if (isVisible(ThisView, User, IncludeEmptyViews, SearchableOnly, ForEdit))
                        {
                            Ret.Add(ThisView.ViewId, ThisView);
                        }
                        else
                        {
                            RowsToRemove.Add(Row);
                        }
                    } // foreach( DataRow Row in ViewsTable.Rows )
                    foreach (DataRow Row in RowsToRemove)
                    {
                        ViewsTable.Rows.Remove(Row);
                    }
                } // if( null == LimitToViews || LimitToViews.Count > 0 )
            }     // if( null != User && CswTools.IsPrimaryKey( User.UserId ) && CswTools.IsPrimaryKey( User.RoleId ) )

            _CswNbtResources.logTimerResult("CswNbtView.getVisibleViews() finished", VisibleViewsTimer.ElapsedDurationInSecondsAsString);

            return(Ret);
        }
        /// <summary>
        /// Get a DataTable of all views in the database
        /// </summary>
        public DataTable getAllViews()
        {
            CswStaticSelect ViewsSelect = _CswNbtResources.makeCswStaticSelect("CswNbtViewSelect.getAllViews_select", "getAllViewInfo");

            return(ViewsSelect.getTable());
        }