public virtual bool Remove(XLinkItemRemoveMode mode)
        {
            if (mode == XLinkItemRemoveMode.LinkAndTargetRecord)
            {
                // We first need to check if the current table x-linked to this entity can actually be deleted.
                // It may not be possible to do so, if other items are x-linked to it.
                if (!CanRemoveTargetRecord())
                {
                    return(false);
                }

                // Apparently it is OK to delete the linked record, so we remove it.
                CurrentTargetRow.Delete();
            }

            // Now we remove the assignment record, which removes the x-link
            CurrentRow.Delete();

            // We raise an update event
            if (ParentEntity is BusinessEntity entity)
            {
                entity.DataUpdated(string.Empty, CurrentRow.Table.TableName);
            }
            if (ParentCollection is EntitySubItemCollection collection)
            {
                collection.DataUpdated(string.Empty, CurrentRow);
            }

            return(true);
        }
Exemplo n.º 2
0
        }//fillTableWithArbitraryData()

        public void deleteArbitraryTableData(string TableName)
        {
            CswTableUpdate CswTableUpdate = _CswNbtSchemaModTrnsctn.makeCswTableUpdate("fillTableWtithArbitraryData_update", TableName);
            DataTable      DataTable      = CswTableUpdate.getTable();

            foreach (DataRow CurrentRow in DataTable.Rows)
            {
                CurrentRow.Delete();
            }

            CswTableUpdate.update(DataTable);
        }//deleteArbitraryTableData()
        /// <summary>
        /// Removes the current item from the collection
        /// </summary>
        public virtual void Remove()
        {
            CurrentRow.Delete();

            // We raise an update event
            if (ParentEntity is BusinessEntity entity)
            {
                entity.DataUpdated(string.Empty, CurrentRow.Table.TableName);
            }
            if (ParentCollection is EntitySubItemCollection collection)
            {
                collection.DataUpdated(string.Empty, CurrentRow);
            }
        }
        protected override void SetStatusOfRows(DataTable TableForStatus,
                                                string TextOfCheckingOfDeleting, string TextOfCheckingOfExisting, DbParameter[] ParametersOfCommand)
        {
            //
            try
            {
                //
                TableForStatus.Columns.Add("TMP_Status", typeof(string));
                //
                TableForStatus.AcceptChanges();
                foreach (DataRow CurrentRow in TableForStatus.Rows)
                {
                    CurrentRow.SetModified();
                }
                //
                string TextOfExistingOfCommand = "";
                if (TextOfCheckingOfDeleting != "")
                {
                    TextOfExistingOfCommand = String.Format(
                        "IF ({0}) SET @Status = 'REM' ELSE IF ({1}) SET @Status = 'MOD' ELSE SET @Status = 'ADD';",
                        TextOfCheckingOfDeleting, TextOfCheckingOfExisting);
                }
                else
                {
                    TextOfExistingOfCommand = String.Format(
                        "IF ({0}) SET @Status = 'MOD' ELSE SET @Status = 'ADD';",
                        TextOfCheckingOfExisting);
                }
                //
                DbParameter[] ParametersOfExistingCommand =
                    new DbParameter[ParametersOfCommand.Length + 1];
                for (int i = 0; i < ParametersOfCommand.Length; i++)
                {
                    ParametersOfExistingCommand[i] = ParametersOfCommand[i];
                }
                ParametersOfExistingCommand[ParametersOfCommand.Length] =
                    new SqlParameter("@Status", SqlDbType.VarChar, 3, "TMP_Status");
                //
                DbCommand CommandOfExisting = CreatingCommand(TextOfExistingOfCommand, ParametersOfExistingCommand);
                CommandOfExisting.Parameters["@Status"].Direction = ParameterDirection.Output;
                SqlDataAdapter ReadingStatus = new SqlDataAdapter();
                ReadingStatus.UpdateCommand = (SqlCommand)CommandOfExisting;
                //
                ReadingStatus.Update(TableForStatus);
                //
                foreach (DataRow CurrentRow in TableForStatus.Rows)
                {
                    switch (CurrentRow["TMP_Status"].ToString())
                    {
                    case "REM":
                        CurrentRow.Delete();
                        break;

                    case "ADD":
                        CurrentRow.SetAdded();
                        break;

                    case "MOD":
                        CurrentRow.SetModified();
                        break;
                    }
                }
                //
                TableForStatus.Columns.Remove("TMP_Status");
            }
            catch (Exception E) { ReturningMessageAboutError("Ошибка при чтении статуса строк", E, false); }
        }
Exemplo n.º 5
0
        public void updateDemoData( List<string> node_ids_convert_to_non_demo, List<string> view_ids_convert_to_non_demo, List<string> node_ids_remove, List<string> view_ids_remove, List<string> Errors )
        {

            //*****************
            //just in case: converto-to-non-demo takes precendence over delete?
            foreach( string CurrentViewId in view_ids_convert_to_non_demo )
            {
                if( view_ids_remove.Contains( CurrentViewId ) )
                {
                    view_ids_remove.Remove( CurrentViewId );
                }
            }

            foreach( string CurrentnodeId in node_ids_convert_to_non_demo )
            {
                if( node_ids_remove.Contains( CurrentnodeId ) )
                {
                    node_ids_remove.Remove( CurrentnodeId );
                }
            }



            //**********************
            // Views 
            if( view_ids_convert_to_non_demo.Count > 0 )
            {

                CswCommaDelimitedString ViewIdsToConvert = new CswCommaDelimitedString();
                ViewIdsToConvert.FromArray( view_ids_convert_to_non_demo.ToArray() );

                try
                {

                    CswTableUpdate ConvertViewsToNonDemoUpdate = _CswNbtResources.makeCswTableUpdate( "update_views_to_non_demo", "node_views" );
                    DataTable ViewsTable = ConvertViewsToNonDemoUpdate.getTable( " where nodeviewid in (" + ViewIdsToConvert.ToString() + ")" );
                    foreach( DataRow CurrentRow in ViewsTable.Rows )
                    {
                        CurrentRow["isdemo"] = CswConvert.ToDbVal( false );
                    }

                    ConvertViewsToNonDemoUpdate.update( ViewsTable );
                }
                catch( Exception Exception )
                {

                    Errors.Add( "Error converting demo views " + ViewIdsToConvert.ToString() + " to non-demo: " + Exception.Message );
                }

            }//if we have view to udpate


            if( view_ids_remove.Count > 0 )
            {

                CswCommaDelimitedString ViewIdsToRemove = new CswCommaDelimitedString();
                ViewIdsToRemove.FromArray( view_ids_remove.ToArray() );
                try
                {

                    CswTableUpdate ConvertViewsToNonDemoUpdate = _CswNbtResources.makeCswTableUpdate( "delete_demo_views", "node_views" );
                    string WhereClause = " where nodeviewid in (" + ViewIdsToRemove.ToString() + ")";
                    DataTable ViewsTable = ConvertViewsToNonDemoUpdate.getTable( WhereClause );
                    foreach( DataRow CurrentRow in ViewsTable.Rows )
                    {
                        CurrentRow.Delete();
                    }

                    ConvertViewsToNonDemoUpdate.update( ViewsTable );
                }
                catch( Exception Exception )
                {

                    Errors.Add( "Error removing demo views " + ViewIdsToRemove.ToString() + " : " + Exception.Message );
                }

            }//if we have view to udpate


            //***************************************************************
            // ***** Nodes
            //**********************
            if( node_ids_convert_to_non_demo.Count > 0 )
            {

                CswDelimitedString NodesIdsToconvert = new CswCommaDelimitedString();
                NodesIdsToconvert.FromArray( node_ids_convert_to_non_demo.ToArray() );

                try
                {

                    CswTableUpdate ConvertNodesToNonDemoUpdate = _CswNbtResources.makeCswTableUpdate( "update_Nodes_to_non_demo", "nodes" );
                    DataTable NodesTable = ConvertNodesToNonDemoUpdate.getTable( " where Nodeid in (" + NodesIdsToconvert + ")" );
                    foreach( DataRow CurrentRow in NodesTable.Rows )
                    {
                        CurrentRow["isdemo"] = CswConvert.ToDbVal( false );
                    }

                    ConvertNodesToNonDemoUpdate.update( NodesTable );
                }

                catch( Exception Exception )
                {

                    Errors.Add( "Error converting nodes " + NodesIdsToconvert.ToString() + " to non-demo: " + Exception.Message );
                }

            }//if we have nodes to convert


            if( node_ids_remove.Count > 0 )
            {
                foreach( string NodeIdToRemove in node_ids_remove )
                {
                    try
                    {
                        CswPrimaryKey NodePrimeKey = new CswPrimaryKey();
                        NodePrimeKey.FromString( "nodes_" + NodeIdToRemove );
                        CswNbtNode CurrentNode = _CswNbtResources.Nodes[NodePrimeKey];
                        if( null != CurrentNode )
                        {
                            CurrentNode.delete();
                        }

                    }
                    catch( Exception Exception )
                    {
                        string Error = "Error removing nodes to non-demo: " + Exception.Message;
                        Errors.Add( Error );
                    }

                }//iterate node ids to remove

            }//if we have nodes to delete

        }//updateDemoData()