/// <summary>
        /// This method returns the Primary Key for a table.
        /// This method is for single field Primary Keys, not
        /// Composite primary keys consisting of multiple fields.
        /// You can manually add a second jparameter if needed for now.
        /// </summary>
        public DTNField FindPrimaryKey(DTNTable table)
        {
            // initial value
            DTNField primaryKey = null;

            // if the table has fields
            if ((NullHelper.Exists(table)) && (table.HasFields))
            {
                // iterate the fields
                foreach (DTNField field in table.Fields)
                {
                    // the field is a PrimaryKey
                    if (field.PrimaryKey)
                    {
                        // set the reeturn value
                        primaryKey = field;

                        // no reason to stick around until multiple primary key fields is handled.
                        break;
                    }
                }
            }

            // return value
            return(primaryKey);
        }
        /// <summary>
        /// This method prepares this control for creating or editing Custom Readers.
        /// </summary>
        public void Setup(Project openProject, DTNTable selectedTable, CustomReader selectedReader = null)
        {
            // store the args
            OpenProject         = openProject;
            this.SelectedTable  = selectedTable;
            this.SelectedReader = selectedReader;

            // If the SelectedTable object exists
            if (this.HasSelectedTable)
            {
                // Set the TableName
                this.TableControl.Text = this.SelectedTable.TableName;

                // Load the FieldSets (where ReaderMode equals true)
                this.FieldSetControl.LoadItems(this.SelectedTable.ReaderFieldSets);
            }
            else
            {
                // Set the TableName
                this.TableControl.Text = "";
            }

            // Display the readers
            DisplayCustomReaders();

            // Display the SelectedCustomReader
            DisplaySelectedCustomReader();
        }
        /// <summary>
        /// This method Setups this control
        /// </summary>
        public void Setup(Project project, DTNTable table)
        {
            // store the args
            Project = project;
            Table   = table;

            // if the value for HasServicesFolder is false
            if (!HasServicesFolder)
            {
                // Set the DefaultServicesFolder on the project so the Save button becomes enabled
                Project.ServicesFolder = Path.Combine(Project.ProjectFolder, @"DataGateway\Services");
            }

            // Create a new instance of a 'ProjectsWriter' object.
            ProjectsWriter writer = new ProjectsWriter();

            // Set the InitialProject text so we can compare later
            this.InitialProject = writer.ExportProject(this.Project);

            // Display the Text
            ServicesFolderControl.Text = Project.ServicesFolder;

            // Fix a bug in my control to centger the buttons
            this.SaveCancelControl.CancelButtonTextAlign = ContentAlignment.MiddleCenter;
            this.SaveCancelControl.SaveButtonTextAlign   = ContentAlignment.MiddleCenter;

            // Change the text of the CreateBlazorServicesButton
            this.CreateBlazorServicesButton.Text = "Create Data Services For " + Table.TableName;

            // Setup the CancelButton to use Done instead of Cancel
            this.SaveCancelControl.SetupCancelButton("Done", 80);

            // Enable or disable controls
            UIEnable();
        }
Beispiel #4
0
        /// <summary>
        /// Saves a 'DTNTable' object into the database.
        /// This method calls the 'Insert' or 'Update' method.
        /// </summary>
        /// <param name='dTNTable'>The 'DTNTable' object to save.</param>
        /// <returns>True if successful or false if not.</returns>
        public bool Save(ref DTNTable dTNTable)
        {
            // Initial value
            bool saved = false;

            // If the dTNTable exists.
            if (dTNTable != null)
            {
                // Is this a new DTNTable
                if (dTNTable.IsNew)
                {
                    // Insert new DTNTable
                    int newIdentity = this.Insert(dTNTable);

                    // if insert was successful
                    if (newIdentity > 0)
                    {
                        // Update Identity
                        dTNTable.UpdateIdentity(newIdentity);

                        // Set return value
                        saved = true;
                    }
                }
                else
                {
                    // Update DTNTable
                    saved = this.Update(dTNTable);
                }
            }

            // return value
            return(saved);
        }
Beispiel #5
0
        /// <summary>
        /// This method finds a  'DTNTable' object.
        /// This method uses the 'DTNTable_Find' procedure.
        /// </summary>
        /// <returns>A 'DTNTable' object.</returns>
        /// </summary>
        public DTNTable FindDTNTable(FindDTNTableStoredProcedure findDTNTableProc, DataConnector databaseConnector)
        {
            // Initial Value
            DTNTable dTNTable = null;

            // Verify database connection is connected
            if ((databaseConnector != null) && (databaseConnector.Connected))
            {
                // First Get Dataset
                DataSet dTNTableDataSet = this.DataHelper.LoadDataSet(findDTNTableProc, databaseConnector);

                // Verify DataSet Exists
                if (dTNTableDataSet != null)
                {
                    // Get DataTable From DataSet
                    DataRow row = this.DataHelper.ReturnFirstRow(dTNTableDataSet);

                    // if row exists
                    if (row != null)
                    {
                        // Load DTNTable
                        dTNTable = DTNTableReader.Load(row);
                    }
                }
            }

            // return value
            return(dTNTable);
        }
        /// <summary>
        /// This method deletes a 'DTNTable' object.
        /// </summary>
        /// <param name='List<PolymorphicObject>'>The 'DTNTable' to delete.
        /// <returns>A PolymorphicObject object with a Boolean value.
        internal PolymorphicObject DeleteDTNTable(List <PolymorphicObject> parameters, DataConnector dataConnector)
        {
            // Initial Value
            PolymorphicObject returnObject = new PolymorphicObject();

            // If the data connection is connected
            if ((dataConnector != null) && (dataConnector.Connected == true))
            {
                // Create Delete StoredProcedure
                DeleteDTNTableStoredProcedure deleteDTNTableProc = null;

                // verify the first parameters is a(n) 'DTNTable'.
                if (parameters[0].ObjectValue as DTNTable != null)
                {
                    // Create DTNTable
                    DTNTable dTNTable = (DTNTable)parameters[0].ObjectValue;

                    // verify dTNTable exists
                    if (dTNTable != null)
                    {
                        // Now create deleteDTNTableProc from DTNTableWriter
                        // The DataWriter converts the 'DTNTable'
                        // to the SqlParameter[] array needed to delete a 'DTNTable'.
                        deleteDTNTableProc = DTNTableWriter.CreateDeleteDTNTableStoredProcedure(dTNTable);
                    }
                }

                // Verify deleteDTNTableProc exists
                if (deleteDTNTableProc != null)
                {
                    // Execute Delete Stored Procedure
                    bool deleted = this.DataManager.DTNTableManager.DeleteDTNTable(deleteDTNTableProc, dataConnector);

                    // Create returnObject.Boolean
                    returnObject.Boolean = new NullableBoolean();

                    // If delete was successful
                    if (deleted)
                    {
                        // Set returnObject.Boolean.Value to true
                        returnObject.Boolean.Value = NullableBooleanEnum.True;
                    }
                    else
                    {
                        // Set returnObject.Boolean.Value to false
                        returnObject.Boolean.Value = NullableBooleanEnum.False;
                    }
                }
            }
            else
            {
                // Raise Error Data Connection Not Available
                throw new Exception("The database connection is not available.");
            }

            // return value
            return(returnObject);
        }
        /// <summary>
        /// This method finds a 'DTNTable' object.
        /// </summary>
        /// <param name='List<PolymorphicObject>'>The 'DTNTable' to delete.
        /// <returns>A PolymorphicObject object with a Boolean value.
        internal PolymorphicObject FindDTNTable(List <PolymorphicObject> parameters, DataConnector dataConnector)
        {
            // Initial Value
            PolymorphicObject returnObject = new PolymorphicObject();

            // locals
            DTNTable dTNTable = null;

            // If the data connection is connected
            if ((dataConnector != null) && (dataConnector.Connected == true))
            {
                // Create Find StoredProcedure
                FindDTNTableStoredProcedure findDTNTableProc = null;

                // verify the first parameters is a 'DTNTable'.
                if (parameters[0].ObjectValue as DTNTable != null)
                {
                    // Get DTNTableParameter
                    DTNTable paramDTNTable = (DTNTable)parameters[0].ObjectValue;

                    // verify paramDTNTable exists
                    if (paramDTNTable != null)
                    {
                        // Now create findDTNTableProc from DTNTableWriter
                        // The DataWriter converts the 'DTNTable'
                        // to the SqlParameter[] array needed to find a 'DTNTable'.
                        findDTNTableProc = DTNTableWriter.CreateFindDTNTableStoredProcedure(paramDTNTable);
                    }

                    // Verify findDTNTableProc exists
                    if (findDTNTableProc != null)
                    {
                        // Execute Find Stored Procedure
                        dTNTable = this.DataManager.DTNTableManager.FindDTNTable(findDTNTableProc, dataConnector);

                        // if dataObject exists
                        if (dTNTable != null)
                        {
                            // set returnObject.ObjectValue
                            returnObject.ObjectValue = dTNTable;
                        }
                    }
                }
                else
                {
                    // Raise Error Data Connection Not Available
                    throw new Exception("The database connection is not available.");
                }
            }

            // return value
            return(returnObject);
        }
        /// <summary>
        /// This method fetches all 'DTNTable' objects.
        /// </summary>
        /// <param name='List<PolymorphicObject>'>The 'DTNTable' to delete.
        /// <returns>A PolymorphicObject object with all  'DTNTables' objects.
        internal PolymorphicObject FetchAll(List <PolymorphicObject> parameters, DataConnector dataConnector)
        {
            // Initial Value
            PolymorphicObject returnObject = new PolymorphicObject();

            // locals
            List <DTNTable> dTNTableListCollection = null;

            // Create FetchAll StoredProcedure
            FetchAllDTNTablesStoredProcedure fetchAllProc = null;

            // If the data connection is connected
            if ((dataConnector != null) && (dataConnector.Connected == true))
            {
                // Get DTNTableParameter
                // Declare Parameter
                DTNTable paramDTNTable = null;

                // verify the first parameters is a(n) 'DTNTable'.
                if (parameters[0].ObjectValue as DTNTable != null)
                {
                    // Get DTNTableParameter
                    paramDTNTable = (DTNTable)parameters[0].ObjectValue;
                }

                // Now create FetchAllDTNTablesProc from DTNTableWriter
                fetchAllProc = DTNTableWriter.CreateFetchAllDTNTablesStoredProcedure(paramDTNTable);
            }

            // Verify fetchAllProc exists
            if (fetchAllProc != null)
            {
                // Execute FetchAll Stored Procedure
                dTNTableListCollection = this.DataManager.DTNTableManager.FetchAllDTNTables(fetchAllProc, dataConnector);

                // if dataObjectCollection exists
                if (dTNTableListCollection != null)
                {
                    // set returnObject.ObjectValue
                    returnObject.ObjectValue = dTNTableListCollection;
                }
            }
            else
            {
                // Raise Error Data Connection Not Available
                throw new Exception("The database connection is not available.");
            }

            // return value
            return(returnObject);
        }
Beispiel #9
0
        /// <summary>
        /// Deletes a 'DTNTable' from the database
        /// This method calls the DataBridgeManager to execute the delete using the
        /// procedure 'DTNTable_Delete'.
        /// </summary>
        /// <param name='dtntable'>The 'DTNTable' to delete.</param>
        /// <returns>True if the delete is successful or false if not.</returns>
        public bool Delete(DTNTable tempDTNTable)
        {
            // locals
            bool deleted = false;

            // Get information for calling 'DataBridgeManager.PerformDataOperation' method.
            string methodName = "DeleteDTNTable";
            string objectName = "ApplicationLogicComponent.Controllers";

            try
            {
                // verify tempdTNTable exists before attemptintg to delete
                if (tempDTNTable != null)
                {
                    // Create Delegate For DataOperation
                    ApplicationController.DataOperationMethod deleteDTNTableMethod = this.AppController.DataBridge.DataOperations.DTNTableMethods.DeleteDTNTable;

                    // Create parameters for this method
                    List <PolymorphicObject> parameters = CreateDTNTableParameter(tempDTNTable);

                    // Perform DataOperation
                    PolymorphicObject returnObject = this.AppController.DataBridge.PerformDataOperation(methodName, objectName, deleteDTNTableMethod, parameters);

                    // If return object exists
                    if (returnObject != null)
                    {
                        // Test For True
                        if (returnObject.Boolean.Value == NullableBooleanEnum.True)
                        {
                            // Set Deleted To True
                            deleted = true;
                        }
                    }
                }
            }
            catch (Exception error)
            {
                // If ErrorProcessor exists
                if (this.ErrorProcessor != null)
                {
                    // Log the current error
                    this.ErrorProcessor.LogError(methodName, objectName, error);
                }
            }

            // return value
            return(deleted);
        }
Beispiel #10
0
        /// <summary>
        /// This method creates the parameter for a 'DTNTable' data operation.
        /// </summary>
        /// <param name='dtntable'>The 'DTNTable' to use as the first
        /// parameter (parameters[0]).</param>
        /// <returns>A List<PolymorphicObject> collection.</returns>
        private List <PolymorphicObject> CreateDTNTableParameter(DTNTable dTNTable)
        {
            // Initial Value
            List <PolymorphicObject> parameters = new List <PolymorphicObject>();

            // Create PolymorphicObject to hold the parameter
            PolymorphicObject parameter = new PolymorphicObject();

            // Set parameter.ObjectValue
            parameter.ObjectValue = dTNTable;

            // Add userParameter to parameters
            parameters.Add(parameter);

            // return value
            return(parameters);
        }
        /// <summary>
        /// This method creates the sql Parameter[] array
        /// that holds the primary key value.
        /// </summary>
        /// <param name='dTNTable'>The 'DTNTable' to get the primary key of.</param>
        /// <returns>A SqlParameter[] array which contains the primary key value.
        /// to delete.</returns>
        internal static SqlParameter[] CreatePrimaryKeyParameter(DTNTable dTNTable)
        {
            // Initial Value
            SqlParameter[] parameters = new SqlParameter[1];

            // verify user exists
            if (dTNTable != null)
            {
                // Create PrimaryKey Parameter
                SqlParameter @TableId = new SqlParameter("@TableId", dTNTable.TableId);

                // Set parameters[0] to @TableId
                parameters[0] = @TableId;
            }

            // return value
            return(parameters);
        }
        /// <summary>
        /// This method creates an instance of a
        /// 'FindDTNTableStoredProcedure' object and
        /// creates the sql parameter[] array needed
        /// to execute the procedure 'DTNTable_Find'.
        /// </summary>
        /// <param name="dTNTable">The 'DTNTable' to use to
        /// get the primary key parameter.</param>
        /// <returns>An instance of an FetchUserStoredProcedure</returns>
        public static FindDTNTableStoredProcedure CreateFindDTNTableStoredProcedure(DTNTable dTNTable)
        {
            // Initial Value
            FindDTNTableStoredProcedure findDTNTableStoredProcedure = null;

            // verify dTNTable exists
            if (dTNTable != null)
            {
                // Instanciate findDTNTableStoredProcedure
                findDTNTableStoredProcedure = new FindDTNTableStoredProcedure();

                // Now create parameters for this procedure
                findDTNTableStoredProcedure.Parameters = CreatePrimaryKeyParameter(dTNTable);
            }

            // return value
            return(findDTNTableStoredProcedure);
        }
Beispiel #13
0
        /// <summary>
        /// Finds a 'DTNTable' object by the primary key.
        /// This method used the DataBridgeManager to execute the 'Find' using the
        /// procedure 'DTNTable_Find'</param>
        /// </summary>
        /// <param name='tempDTNTable'>A temporary DTNTable for passing values.</param>
        /// <returns>A 'DTNTable' object if found else a null 'DTNTable'.</returns>
        public DTNTable Find(DTNTable tempDTNTable)
        {
            // Initial values
            DTNTable dTNTable = null;

            // Get information for calling 'DataBridgeManager.PerformDataOperation' method.
            string methodName = "Find";
            string objectName = "ApplicationLogicComponent.Controllers";

            try
            {
                // If object exists
                if (tempDTNTable != null)
                {
                    // Create DataOperation
                    ApplicationController.DataOperationMethod findMethod = this.AppController.DataBridge.DataOperations.DTNTableMethods.FindDTNTable;

                    // Create parameters for this method
                    List <PolymorphicObject> parameters = CreateDTNTableParameter(tempDTNTable);

                    // Perform DataOperation
                    PolymorphicObject returnObject = this.AppController.DataBridge.PerformDataOperation(methodName, objectName, findMethod, parameters);

                    // If return object exists
                    if ((returnObject != null) && (returnObject.ObjectValue as DTNTable != null))
                    {
                        // Get ReturnObject
                        dTNTable = (DTNTable)returnObject.ObjectValue;
                    }
                }
            }
            catch (Exception error)
            {
                // If ErrorProcessor exists
                if (this.ErrorProcessor != null)
                {
                    // Log the current error
                    this.ErrorProcessor.LogError(methodName, objectName, error);
                }
            }

            // return value
            return(dTNTable);
        }
Beispiel #14
0
        /// <summary>
        /// Insert a 'DTNTable' object into the database.
        /// This method uses the DataBridgeManager to execute the 'Insert' using the
        /// procedure 'DTNTable_Insert'.</param>
        /// </summary>
        /// <param name='dTNTable'>The 'DTNTable' object to insert.</param>
        /// <returns>The id (int) of the new  'DTNTable' object that was inserted.</returns>
        public int Insert(DTNTable dTNTable)
        {
            // Initial values
            int newIdentity = -1;

            // Get information for calling 'DataBridgeManager.PerformDataOperation' method.
            string methodName = "Insert";
            string objectName = "ApplicationLogicComponent.Controllers";

            try
            {
                // If DTNTableexists
                if (dTNTable != null)
                {
                    ApplicationController.DataOperationMethod insertMethod = this.AppController.DataBridge.DataOperations.DTNTableMethods.InsertDTNTable;

                    // Create parameters for this method
                    List <PolymorphicObject> parameters = CreateDTNTableParameter(dTNTable);

                    // Perform DataOperation
                    PolymorphicObject returnObject = this.AppController.DataBridge.PerformDataOperation(methodName, objectName, insertMethod, parameters);

                    // If return object exists
                    if (returnObject != null)
                    {
                        // Set return value
                        newIdentity = returnObject.IntegerValue;
                    }
                }
            }
            catch (Exception error)
            {
                // If ErrorProcessor exists
                if (this.ErrorProcessor != null)
                {
                    // Log the current error
                    this.ErrorProcessor.LogError(methodName, objectName, error);
                }
            }

            // return value
            return(newIdentity);
        }
Beispiel #15
0
        /// <summary>
        /// This method Updates a 'DTNTable' object in the database.
        /// This method used the DataBridgeManager to execute the 'Update' using the
        /// procedure 'DTNTable_Update'.</param>
        /// </summary>
        /// <param name='dTNTable'>The 'DTNTable' object to update.</param>
        /// <returns>True if successful else false if not.</returns>
        public bool Update(DTNTable dTNTable)
        {
            // Initial value
            bool saved = false;

            // Get information for calling 'DataBridgeManager.PerformDataOperation' method.
            string methodName = "Update";
            string objectName = "ApplicationLogicComponent.Controllers";

            try
            {
                if (dTNTable != null)
                {
                    // Create Delegate
                    ApplicationController.DataOperationMethod updateMethod = this.AppController.DataBridge.DataOperations.DTNTableMethods.UpdateDTNTable;

                    // Create parameters for this method
                    List <PolymorphicObject> parameters = CreateDTNTableParameter(dTNTable);
                    // Perform DataOperation
                    PolymorphicObject returnObject = this.AppController.DataBridge.PerformDataOperation(methodName, objectName, updateMethod, parameters);

                    // If return object exists
                    if ((returnObject != null) && (returnObject.Boolean != null) && (returnObject.Boolean.Value == NullableBooleanEnum.True))
                    {
                        // Set saved to true
                        saved = true;
                    }
                }
            }
            catch (Exception error)
            {
                // If ErrorProcessor exists
                if (this.ErrorProcessor != null)
                {
                    // Log the current error
                    this.ErrorProcessor.LogError(methodName, objectName, error);
                }
            }

            // return value
            return(saved);
        }
        /// <summary>
        /// This method loads a 'DTNTable' object
        /// from the dataRow passed in.
        /// </summary>
        /// <param name='dataRow'>The 'DataRow' to load from.</param>
        /// <returns>A 'DTNTable' DataObject.</returns>
        public static DTNTable Load(DataRow dataRow)
        {
            // Initial Value
            DTNTable dTNTable = new DTNTable();

            // Create field Integers
            int classFileNamefield         = 0;
            int classNamefield             = 1;
            int createBindingCallbackfield = 2;
            int databaseIdfield            = 3;
            int excludefield      = 4;
            int excludedfield     = 5;
            int isViewfield       = 6;
            int projectIdfield    = 7;
            int scopefield        = 8;
            int serializablefield = 9;
            int tableIdfield      = 10;
            int tableNamefield    = 11;

            try
            {
                // Load Each field
                dTNTable.ClassFileName         = DataHelper.ParseString(dataRow.ItemArray[classFileNamefield]);
                dTNTable.ClassName             = DataHelper.ParseString(dataRow.ItemArray[classNamefield]);
                dTNTable.CreateBindingCallback = DataHelper.ParseBoolean(dataRow.ItemArray[createBindingCallbackfield], false);
                dTNTable.DatabaseId            = DataHelper.ParseInteger(dataRow.ItemArray[databaseIdfield], 0);
                dTNTable.Exclude      = DataHelper.ParseBoolean(dataRow.ItemArray[excludefield], false);
                dTNTable.Excluded     = DataHelper.ParseBoolean(dataRow.ItemArray[excludedfield], false);
                dTNTable.IsView       = DataHelper.ParseBoolean(dataRow.ItemArray[isViewfield], false);
                dTNTable.ProjectId    = DataHelper.ParseInteger(dataRow.ItemArray[projectIdfield], 0);
                dTNTable.Scope        = (ScopeEnum)DataHelper.ParseInteger(dataRow.ItemArray[scopefield], 0);
                dTNTable.Serializable = DataHelper.ParseBoolean(dataRow.ItemArray[serializablefield], false);
                dTNTable.UpdateIdentity(DataHelper.ParseInteger(dataRow.ItemArray[tableIdfield], 0));
                dTNTable.TableName = DataHelper.ParseString(dataRow.ItemArray[tableNamefield]);
            }
            catch
            {
            }

            // return value
            return(dTNTable);
        }
        /// <summary>
        /// This method loads a collection of 'DTNTable' objects.
        /// from the dataTable.Rows object passed in.
        /// </summary>
        /// <param name='dataTable'>The 'DataTable.Rows' to load from.</param>
        /// <returns>A DTNTable Collection.</returns>
        public static List <DTNTable> LoadCollection(DataTable dataTable)
        {
            // Initial Value
            List <DTNTable> dTNTables = new List <DTNTable>();

            try
            {
                // Load Each row In DataTable
                foreach (DataRow row in dataTable.Rows)
                {
                    // Create 'DTNTable' from rows
                    DTNTable dTNTable = Load(row);

                    // Add this object to collection
                    dTNTables.Add(dTNTable);
                }
            }
            catch
            {
            }

            // return value
            return(dTNTables);
        }
Beispiel #18
0
        /// <summary>
        /// This method converts a Data Table to a DTNTable for storing some of the scheme info in SQL.
        /// </summary>
        public static DataJuggler.Net.DataTable ConvertDataTable(DTNTable sourceTable, Project project)
        {
            // initial value
            DataJuggler.Net.DataTable table = null;

            // if the sourceTable exists
            if (NullHelper.Exists(sourceTable))
            {
                // Create a new instance of a 'DTNTable' object.
                table = new DataJuggler.Net.DataTable();

                // Set any properties to store
                table.ClassFileName = sourceTable.ClassFileName;
                table.ClassName     = sourceTable.ClassName;
                table.IsView        = sourceTable.IsView;

                // Convert the Fields
                table.Fields       = ConvertDataFields(sourceTable.Fields);
                table.Serializable = sourceTable.Serializable;
                table.Name         = sourceTable.TableName;

                // New field used with Blazor
                if ((NullHelper.Exists(project)) && (project.EnableBlazorFeatures) && (project.BindingCallbackOption != BindingCallbackOptionEnum.No_Binding))
                {
                    // if the Project has Create Binding, this implies all tables or if the sourceTable has CreatingBindingCallback set to true
                    if ((project.BindingCallbackOption == BindingCallbackOptionEnum.Create_Binding) || (sourceTable.CreateBindingCallback))
                    {
                        // set the value for CreateBindingCallback to true
                        table.CreateBindingCallback = true;
                    }
                }
            }

            // return value
            return(table);
        }
Beispiel #19
0
        /// <summary>
        /// This method converts a Data Table to a DTNTable for storing some of the scheme info in SQL.
        /// </summary>
        public static DTNTable ConvertDataTable(DataTable sourceTable, Project project, DTNDatabase dtnDatabase)
        {
            // initial value
            DTNTable table = null;

            // if the sourceTable exists and there are one or more Databases for this project
            if ((NullHelper.Exists(sourceTable, project, dtnDatabase)) && (project.HasDatabases) && (ListHelper.HasOneOrMoreItems(project.Databases)))
            {
                // Create a new instance of a 'DTNTable' object.
                table = new DTNTable();

                // Set any properties to store
                table.ClassFileName         = sourceTable.ClassFileName;
                table.ClassName             = sourceTable.ClassName;
                table.Exclude               = sourceTable.Exclude;
                table.CreateBindingCallback = sourceTable.CreateBindingCallback;

                // Only 1 Database is officially supported now
                table.DatabaseId = project.Databases[0].DatabaseId;

                // Convert the Fields
                table.Fields       = ConvertDataFields(sourceTable.Fields, table.DatabaseId, project.ProjectId, sourceTable.TableId);
                table.IsView       = sourceTable.IsView;
                table.ProjectId    = project.ProjectId;
                table.Serializable = sourceTable.Serializable;
                table.TableName    = sourceTable.Name;

                // Update 3.26.2019: The TableId does not actually exist on the DataTable.
                // This will only be set when a project is reopened so that duplicate tables
                // are not attempted to be inserted.
                table.UpdateIdentity(sourceTable.TableId);
            }

            // return value
            return(table);
        }
 /// <summary>
 /// Prepares the CustomMethodEditor to be run
 /// </summary>
 public void Setup(DTNTable table, Project selectedProject, Method selectedMethod = null)
 {
     // Pass in the table to the control
     this.CustomMethodEditor.Setup(table, selectedProject, selectedMethod);
 }
        /// <summary>
        /// This method creates an instance of a
        /// 'FetchAllDTNTablesStoredProcedure' object and
        /// creates the sql parameter[] array needed
        /// to execute the procedure 'DTNTable_FetchAll'.
        /// </summary>
        /// <returns>An instance of a(n) 'FetchAllDTNTablesStoredProcedure' object.</returns>
        public static new FetchAllDTNTablesStoredProcedure CreateFetchAllDTNTablesStoredProcedure(DTNTable dTNTable)
        {
            // Initial value
            FetchAllDTNTablesStoredProcedure fetchAllDTNTablesStoredProcedure = new FetchAllDTNTablesStoredProcedure();

            // if the dTNTable object exists
            if (dTNTable != null)
            {
                // if LoadByProjectId is true
                if (dTNTable.LoadByProjectId)
                {
                    // Change the procedure name
                    fetchAllDTNTablesStoredProcedure.ProcedureName = "DTNTable_FetchAllByProjectId";

                    // Create the @ProjectId parameter
                    fetchAllDTNTablesStoredProcedure.Parameters = SqlParameterHelper.CreateSqlParameters("@ProjectId", dTNTable.ProjectId);
                }
            }

            // return value
            return(fetchAllDTNTablesStoredProcedure);
        }
 /// <summary>
 /// This method prepares the FieldSetEditor control to be shown in OrderByMode
 /// </summary>
 public void SetupForOrderByMode(DTNTable table, FieldSet fieldSet = null)
 {
     // Setup the control
     this.FieldSetEditor.SetupForOrderByMode(table, fieldSet);
 }
        /// <summary>
        /// This method creates an instance of an
        /// 'DeleteDTNTable'StoredProcedure' object and
        /// creates the sql parameter[] array needed
        /// to execute the procedure 'DTNTable_Delete'.
        /// </summary>
        /// <param name="dTNTable">The 'DTNTable' to Delete.</param>
        /// <returns>An instance of a 'DeleteDTNTableStoredProcedure' object.</returns>
        public static new DeleteDTNTableStoredProcedure CreateDeleteDTNTableStoredProcedure(DTNTable table)
        {
            // Initial Value
            DeleteDTNTableStoredProcedure deleteDTNTableStoredProcedure = new DeleteDTNTableStoredProcedure();

            // If the table object exists
            if (table != null)
            {
                // if DeleteAllForProjectId is true and the ProjectId is set
                if ((table.DeleteAllForProjectId) && (table.HasProjectId))
                {
                    // change the procedureName
                    deleteDTNTableStoredProcedure.ProcedureName = "DTNTable_DeleteAllForProject";

                    // Set the @ProjectId parameter
                    deleteDTNTableStoredProcedure.Parameters = SqlParameterHelper.CreateSqlParameters("@ProjectId", table.ProjectId);
                }
                else
                {
                    // Now Create Parameters For The DeleteProc
                    deleteDTNTableStoredProcedure.Parameters = CreatePrimaryKeyParameter(table);
                }
            }

            // return value
            return(deleteDTNTableStoredProcedure);
        }
Beispiel #24
0
 /// <summary>
 /// This method Sets up this control
 /// </summary>
 public void Setup(DTNTable selectedTable, List <Method> methods)
 {
     // store the args
     this.SelectedTable = selectedTable;
     this.MethodsList   = methods;
 }
 /// <summary>
 /// This method prepares this control to be shown.
 /// </summary>
 public void Setup(DTNTable table, bool parameterMode, bool parameterModeReadOnly = false, FieldSet fieldSet = null)
 {
     // Setup the control
     this.FieldSetEditor.Setup(table, parameterMode, parameterModeReadOnly, fieldSet);
 }
Beispiel #26
0
 /// <summary>
 /// method returns a list of
 /// </summary>
 public void Setup(DTNTable selectedTable, List <Method> methods)
 {
     // Setup the control
     this.CustomMethodsEditor.Setup(selectedTable, methods);
 }
        /// <summary>
        /// This method adds all the databases in the current project
        /// to the DataManager (DM).
        /// </summary>
        /// <param name="currentProject"></param>
        public void AddDatabases(ref Project currentProject)
        {
            // Make sure the CurrentProject is set; I think this changed and now the CurrentProject
            // is created earlier.
            if ((CurrentProject == null) || (!CurrentProject.Equals(currentProject)))
            {
                // this has to be set before the DataManager can be created
                this.CurrentProject = currentProject;
            }

            // locals
            Database           database     = null;
            List <Enumeration> enumerations = null;
            List <DTNDatabase> databases    = null;

            // If the currentProject object exists
            if (NullHelper.Exists(currentProject))
            {
                // set the databases
                databases = currentProject.Databases;

                // if the current project has enumerations
                if (ListHelper.HasOneOrMoreItems(currentProject.Enumerations))
                {
                    // get a list of enumerations
                    enumerations = new List <Enumeration>();

                    // if the enumrations exist
                    foreach (Enumeration enumeration in currentProject.Enumerations)
                    {
                        // add thsi enumerations
                        enumerations.Add(enumeration);
                    }
                }
            }

            // if databases exists
            if ((ListHelper.HasOneOrMoreItems(databases)) && (DataManager != null))
            {
                // loop through each database
                foreach (DTNDatabase db in databases)
                {
                    // convert to DataJuggler.Net.Sql database
                    database = ConvertSQLDatabase(db, enumerations);

                    // if the database exists
                    if (database != null)
                    {
                        // If the database has Serializable selected
                        if (db.Serializable)
                        {
                            // Serialize each table
                            foreach (DataTable table in database.Tables)
                            {
                                // Set serializable on the table
                                table.Serializable = true;
                            }
                        }

                        // if there are one or more tables in the current Project
                        if (ListHelper.HasOneOrMoreItems(CurrentProject.Tables))
                        {
                            // iterate the tables
                            foreach (DTNTable table in CurrentProject.Tables)
                            {
                                // attempt to find this table in this database
                                DataTable dataTable = database.Tables.FirstOrDefault(x => x.Name == table.TableName);

                                // If the dataTable object exists
                                if (NullHelper.Exists(dataTable))
                                {
                                    // Store the tableId in dataTable so a save performs an update and not a duplicate insert
                                    dataTable.TableId = table.TableId;

                                    // Set the value for Exclude in the dataTable
                                    dataTable.Exclude = table.Exclude;
                                    dataTable.CreateBindingCallback = table.CreateBindingCallback;

                                    // if this table has one or more fields
                                    if (ListHelper.HasOneOrMoreItems(table.Fields))
                                    {
                                        // iterate the fields
                                        foreach (DTNField field in table.Fields)
                                        {
                                            // We now must find the field in this DataTable
                                            DataField dataField = dataTable.Fields.FirstOrDefault(x => x.FieldName == field.FieldName);

                                            // If the dataField object exists
                                            if (NullHelper.Exists(dataField))
                                            {
                                                // Store the FieldId, which is not really mapped, but when the field is converted
                                                // back to a DTNField, this FieldId is converted if present.
                                                dataField.FieldId = field.FieldId;

                                                // set Exclude
                                                dataField.Exclude = field.Exclude;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        // Add this database
                        this.DataManager.Databases.Add(database);
                    }
                }

                // now we must recreate the currentProject.Tables to match the database
                if ((DataManager != null) && (DataManager.Databases != null) && (DataManager.Databases.Count > 0) && (DataManager.Databases[0].Tables.Count > 0))
                {
                    // create the currentTables
                    List <DTNTable> currentTables = new List <DTNTable>();

                    // iterate the databases
                    foreach (Database db in DataManager.Databases)
                    {
                        // attempt to find the database
                        DTNDatabase dtnDatabase = currentProject.Databases.FirstOrDefault(x => x.DatabaseName == db.Name);

                        // If the dtnDatabase object exists
                        if (NullHelper.Exists(dtnDatabase))
                        {
                            // iterate the tables
                            foreach (DataTable table in db.Tables)
                            {
                                // create the table
                                DTNTable dtnTable = DataConverter.ConvertDataTable(table, currentProject, dtnDatabase);

                                // We must check if we have an existing table already with this name that is excluded
                                DTNTable existingTable = CurrentProject.Tables.FirstOrDefault(x => x.TableName == table.Name);

                                // if the table exists
                                if (NullHelper.Exists(dtnTable))
                                {
                                    // if the existingTable was found
                                    if (NullHelper.Exists(existingTable))
                                    {
                                        // Update the value for exclude
                                        dtnTable.Exclude = existingTable.Exclude;
                                        dtnTable.CreateBindingCallback = existingTable.CreateBindingCallback;
                                    }

                                    // Add this table
                                    currentTables.Add(dtnTable);
                                }
                            }
                        }
                    }

                    // Now set the CurrentProject.Tables back
                    currentProject.Tables = currentTables;
                }
            }
        }
        /// <summary>
        /// This method creates an instance of an
        /// 'UpdateDTNTableStoredProcedure' object and
        /// creates the sql parameter[] array needed
        /// to execute the procedure 'DTNTable_Update'.
        /// </summary>
        /// <param name="dTNTable"The 'DTNTable' object to update</param>
        /// <returns>An instance of a 'UpdateDTNTableStoredProcedure</returns>
        public static UpdateDTNTableStoredProcedure CreateUpdateDTNTableStoredProcedure(DTNTable dTNTable)
        {
            // Initial Value
            UpdateDTNTableStoredProcedure updateDTNTableStoredProcedure = null;

            // verify dTNTable exists
            if (dTNTable != null)
            {
                // Instanciate updateDTNTableStoredProcedure
                updateDTNTableStoredProcedure = new UpdateDTNTableStoredProcedure();

                // Now create parameters for this procedure
                updateDTNTableStoredProcedure.Parameters = CreateUpdateParameters(dTNTable);
            }

            // return value
            return(updateDTNTableStoredProcedure);
        }
        /// <summary>
        /// This method creates an instance of a
        /// 'FetchAllDTNTablesStoredProcedure' object and
        /// creates the sql parameter[] array needed
        /// to execute the procedure 'DTNTable_FetchAll'.
        /// </summary>
        /// <returns>An instance of a(n) 'FetchAllDTNTablesStoredProcedure' object.</returns>
        public static FetchAllDTNTablesStoredProcedure CreateFetchAllDTNTablesStoredProcedure(DTNTable dTNTable)
        {
            // Initial value
            FetchAllDTNTablesStoredProcedure fetchAllDTNTablesStoredProcedure = new FetchAllDTNTablesStoredProcedure();

            // return value
            return(fetchAllDTNTablesStoredProcedure);
        }
        /// <summary>
        /// This method creates an instance of an
        /// 'DeleteDTNTable'StoredProcedure' object and
        /// creates the sql parameter[] array needed
        /// to execute the procedure 'DTNTable_Delete'.
        /// </summary>
        /// <param name="dTNTable">The 'DTNTable' to Delete.</param>
        /// <returns>An instance of a 'DeleteDTNTableStoredProcedure' object.</returns>
        public static DeleteDTNTableStoredProcedure CreateDeleteDTNTableStoredProcedure(DTNTable dTNTable)
        {
            // Initial Value
            DeleteDTNTableStoredProcedure deleteDTNTableStoredProcedure = new DeleteDTNTableStoredProcedure();

            // Now Create Parameters For The DeleteProc
            deleteDTNTableStoredProcedure.Parameters = CreatePrimaryKeyParameter(dTNTable);

            // return value
            return(deleteDTNTableStoredProcedure);
        }