Esempio n. 1
0
        /// <summary>
        /// This method returns the Database By Name
        /// </summary>
        public static DTNDatabase FindDatabaseByName(string name, List <DTNDatabase> projectDatabases)
        {
            // initial value
            DTNDatabase database = null;

            // If the projectDatabases collection exists and has one or more items
            if (ListHelper.HasOneOrMoreItems(projectDatabases))
            {
                // Iterate the collection of Database objects
                foreach (DTNDatabase tempDatabase in projectDatabases)
                {
                    // if this is the name being sought
                    if (TextHelper.IsEqual(tempDatabase.DatabaseName, name))
                    {
                        // set the return value
                        database = tempDatabase;

                        // break out of the loop
                        break;
                    }
                }
            }

            // return value
            return(database);
        }
        /// <summary>
        /// This method saves the Project Databases.
        /// </summary>
        public bool SaveProjectDatabases(Gateway gateway)
        {
            // initial value
            bool databasesSaved = false;
            bool tempSaved      = false;

            // if the SelectedProject has Databases
            if ((this.SelectedProject.HasDatabases) && (this.selectedProject.Databases.Count > 0))
            {
                // default to true until a failure happens
                databasesSaved = true;

                // iterate the Databases
                foreach (DTNDatabase database in this.SelectedProject.Databases)
                {
                    // clone the object so it can be saved by reference
                    DTNDatabase tempDatabase = database.Clone();

                    // save the DTNDatabase
                    tempSaved = gateway.SaveDTNDatabase(ref tempDatabase);

                    // if the value for tempSaved is false
                    if (!tempSaved)
                    {
                        // set to false
                        databasesSaved = false;
                    }
                }
            }

            // return value
            return(databasesSaved);
        }
        /// <summary>
        /// This method finds a  'DTNDatabase' object.
        /// This method uses the 'DTNDatabase_Find' procedure.
        /// </summary>
        /// <returns>A 'DTNDatabase' object.</returns>
        /// </summary>
        public DTNDatabase FindDTNDatabase(FindDTNDatabaseStoredProcedure findDTNDatabaseProc, DataConnector databaseConnector)
        {
            // Initial Value
            DTNDatabase dTNDatabase = null;

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

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

                    // if row exists
                    if (row != null)
                    {
                        // Load DTNDatabase
                        dTNDatabase = DTNDatabaseReader.Load(row);
                    }
                }
            }

            // return value
            return(dTNDatabase);
        }
Esempio n. 4
0
        /// <summary>
        /// Saves a 'DTNDatabase' object into the database.
        /// This method calls the 'Insert' or 'Update' method.
        /// </summary>
        /// <param name='dTNDatabase'>The 'DTNDatabase' object to save.</param>
        /// <returns>True if successful or false if not.</returns>
        public bool Save(ref DTNDatabase dTNDatabase)
        {
            // Initial value
            bool saved = false;

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

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

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

            // return value
            return(saved);
        }
Esempio n. 5
0
        /// <summary>
        /// This method deletes a 'DTNDatabase' object.
        /// </summary>
        /// <param name='List<PolymorphicObject>'>The 'DTNDatabase' to delete.
        /// <returns>A PolymorphicObject object with a Boolean value.
        internal PolymorphicObject DeleteDTNDatabase(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
                DeleteDTNDatabaseStoredProcedure deleteDTNDatabaseProc = null;

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

                    // verify dTNDatabase exists
                    if (dTNDatabase != null)
                    {
                        // Now create deleteDTNDatabaseProc from DTNDatabaseWriter
                        // The DataWriter converts the 'DTNDatabase'
                        // to the SqlParameter[] array needed to delete a 'DTNDatabase'.
                        deleteDTNDatabaseProc = DTNDatabaseWriter.CreateDeleteDTNDatabaseStoredProcedure(dTNDatabase);
                    }
                }

                // Verify deleteDTNDatabaseProc exists
                if (deleteDTNDatabaseProc != null)
                {
                    // Execute Delete Stored Procedure
                    bool deleted = this.DataManager.DTNDatabaseManager.DeleteDTNDatabase(deleteDTNDatabaseProc, 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);
        }
Esempio n. 6
0
        /// <summary>
        /// This method finds a 'DTNDatabase' object.
        /// </summary>
        /// <param name='List<PolymorphicObject>'>The 'DTNDatabase' to delete.
        /// <returns>A PolymorphicObject object with a Boolean value.
        internal PolymorphicObject FindDTNDatabase(List <PolymorphicObject> parameters, DataConnector dataConnector)
        {
            // Initial Value
            PolymorphicObject returnObject = new PolymorphicObject();

            // locals
            DTNDatabase dTNDatabase = null;

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

                // verify the first parameters is a 'DTNDatabase'.
                if (parameters[0].ObjectValue as DTNDatabase != null)
                {
                    // Get DTNDatabaseParameter
                    DTNDatabase paramDTNDatabase = (DTNDatabase)parameters[0].ObjectValue;

                    // verify paramDTNDatabase exists
                    if (paramDTNDatabase != null)
                    {
                        // Now create findDTNDatabaseProc from DTNDatabaseWriter
                        // The DataWriter converts the 'DTNDatabase'
                        // to the SqlParameter[] array needed to find a 'DTNDatabase'.
                        findDTNDatabaseProc = DTNDatabaseWriter.CreateFindDTNDatabaseStoredProcedure(paramDTNDatabase);
                    }

                    // Verify findDTNDatabaseProc exists
                    if (findDTNDatabaseProc != null)
                    {
                        // Execute Find Stored Procedure
                        dTNDatabase = this.DataManager.DTNDatabaseManager.FindDTNDatabase(findDTNDatabaseProc, dataConnector);

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

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

            // locals
            List <DTNDatabase> dTNDatabaseListCollection = null;

            // Create FetchAll StoredProcedure
            FetchAllDTNDatabasesStoredProcedure fetchAllProc = null;

            // If the data connection is connected
            if ((dataConnector != null) && (dataConnector.Connected == true))
            {
                // Get DTNDatabaseParameter
                // Declare Parameter
                DTNDatabase paramDTNDatabase = null;

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

                // Now create FetchAllDTNDatabasesProc from DTNDatabaseWriter
                fetchAllProc = DTNDatabaseWriter.CreateFetchAllDTNDatabasesStoredProcedure(paramDTNDatabase);
            }

            // Verify fetchAllProc exists
            if (fetchAllProc != null)
            {
                // Execute FetchAll Stored Procedure
                dTNDatabaseListCollection = this.DataManager.DTNDatabaseManager.FetchAllDTNDatabases(fetchAllProc, dataConnector);

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

            // return value
            return(returnObject);
        }
Esempio n. 8
0
        /// <summary>
        /// Deletes a 'DTNDatabase' from the database
        /// This method calls the DataBridgeManager to execute the delete using the
        /// procedure 'DTNDatabase_Delete'.
        /// </summary>
        /// <param name='dtndatabase'>The 'DTNDatabase' to delete.</param>
        /// <returns>True if the delete is successful or false if not.</returns>
        public bool Delete(DTNDatabase tempDTNDatabase)
        {
            // locals
            bool deleted = false;

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

            try
            {
                // verify tempdTNDatabase exists before attemptintg to delete
                if (tempDTNDatabase != null)
                {
                    // Create Delegate For DataOperation
                    ApplicationController.DataOperationMethod deleteDTNDatabaseMethod = this.AppController.DataBridge.DataOperations.DTNDatabaseMethods.DeleteDTNDatabase;

                    // Create parameters for this method
                    List <PolymorphicObject> parameters = CreateDTNDatabaseParameter(tempDTNDatabase);

                    // Perform DataOperation
                    PolymorphicObject returnObject = this.AppController.DataBridge.PerformDataOperation(methodName, objectName, deleteDTNDatabaseMethod, 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);
        }
Esempio n. 9
0
        /// <summary>
        /// This method creates the parameter for a 'DTNDatabase' data operation.
        /// </summary>
        /// <param name='dtndatabase'>The 'DTNDatabase' to use as the first
        /// parameter (parameters[0]).</param>
        /// <returns>A List<PolymorphicObject> collection.</returns>
        private List <PolymorphicObject> CreateDTNDatabaseParameter(DTNDatabase dTNDatabase)
        {
            // Initial Value
            List <PolymorphicObject> parameters = new List <PolymorphicObject>();

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

            // Set parameter.ObjectValue
            parameter.ObjectValue = dTNDatabase;

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

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

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

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

            // return value
            return(parameters);
        }
Esempio n. 11
0
        /// <summary>
        /// This method returns the Database Id By Name
        /// </summary>
        public static int FindDatabaseIdByName(string name, List <DTNDatabase> projectDatabases)
        {
            // initial value
            int databaseId = 0;

            // attempt to find the database by name
            DTNDatabase database = FindDatabaseByName(name, projectDatabases);

            // If the database object exists
            if (NullHelper.Exists(database))
            {
                // set the return value
                databaseId = database.DatabaseId;
            }

            // return value
            return(databaseId);
        }
Esempio n. 12
0
        /// <summary>
        /// Finds a 'DTNDatabase' object by the primary key.
        /// This method used the DataBridgeManager to execute the 'Find' using the
        /// procedure 'DTNDatabase_Find'</param>
        /// </summary>
        /// <param name='tempDTNDatabase'>A temporary DTNDatabase for passing values.</param>
        /// <returns>A 'DTNDatabase' object if found else a null 'DTNDatabase'.</returns>
        public DTNDatabase Find(DTNDatabase tempDTNDatabase)
        {
            // Initial values
            DTNDatabase dTNDatabase = null;

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

            try
            {
                // If object exists
                if (tempDTNDatabase != null)
                {
                    // Create DataOperation
                    ApplicationController.DataOperationMethod findMethod = this.AppController.DataBridge.DataOperations.DTNDatabaseMethods.FindDTNDatabase;

                    // Create parameters for this method
                    List <PolymorphicObject> parameters = CreateDTNDatabaseParameter(tempDTNDatabase);

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

                    // If return object exists
                    if ((returnObject != null) && (returnObject.ObjectValue as DTNDatabase != null))
                    {
                        // Get ReturnObject
                        dTNDatabase = (DTNDatabase)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(dTNDatabase);
        }
Esempio n. 13
0
        /// <summary>
        /// Insert a 'DTNDatabase' object into the database.
        /// This method uses the DataBridgeManager to execute the 'Insert' using the
        /// procedure 'DTNDatabase_Insert'.</param>
        /// </summary>
        /// <param name='dTNDatabase'>The 'DTNDatabase' object to insert.</param>
        /// <returns>The id (int) of the new  'DTNDatabase' object that was inserted.</returns>
        public int Insert(DTNDatabase dTNDatabase)
        {
            // Initial values
            int newIdentity = -1;

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

            try
            {
                // If DTNDatabaseexists
                if (dTNDatabase != null)
                {
                    ApplicationController.DataOperationMethod insertMethod = this.AppController.DataBridge.DataOperations.DTNDatabaseMethods.InsertDTNDatabase;

                    // Create parameters for this method
                    List <PolymorphicObject> parameters = CreateDTNDatabaseParameter(dTNDatabase);

                    // 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);
        }
Esempio n. 14
0
        /// <summary>
        /// This method Updates a 'DTNDatabase' object in the database.
        /// This method used the DataBridgeManager to execute the 'Update' using the
        /// procedure 'DTNDatabase_Update'.</param>
        /// </summary>
        /// <param name='dTNDatabase'>The 'DTNDatabase' object to update.</param>
        /// <returns>True if successful else false if not.</returns>
        public bool Update(DTNDatabase dTNDatabase)
        {
            // Initial value
            bool saved = false;

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

            try
            {
                if (dTNDatabase != null)
                {
                    // Create Delegate
                    ApplicationController.DataOperationMethod updateMethod = this.AppController.DataBridge.DataOperations.DTNDatabaseMethods.UpdateDTNDatabase;

                    // Create parameters for this method
                    List <PolymorphicObject> parameters = CreateDTNDatabaseParameter(dTNDatabase);
                    // 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 'DTNDatabase' object
        /// from the dataRow passed in.
        /// </summary>
        /// <param name='dataRow'>The 'DataRow' to load from.</param>
        /// <returns>A 'DTNDatabase' DataObject.</returns>
        public static DTNDatabase Load(DataRow dataRow)
        {
            // Initial Value
            DTNDatabase dTNDatabase = new DTNDatabase();

            // Create field Integers
            int authenticationTypefield = 0;
            int connectionStringfield   = 1;
            int databaseIdfield         = 2;
            int databaseNamefield       = 3;
            int databaseTypefield       = 4;
            int dBPasswordfield         = 5;
            int excludefield            = 6;
            int pathfield         = 7;
            int projectIdfield    = 8;
            int serializablefield = 9;
            int serverNamefield   = 10;
            int userIdfield       = 11;

            try
            {
                // Load Each field
                dTNDatabase.AuthenticationType = DataHelper.ParseInteger(dataRow.ItemArray[authenticationTypefield], 0);
                dTNDatabase.ConnectionString   = DataHelper.ParseString(dataRow.ItemArray[connectionStringfield]);
                dTNDatabase.UpdateIdentity(DataHelper.ParseInteger(dataRow.ItemArray[databaseIdfield], 0));
                dTNDatabase.DatabaseName = DataHelper.ParseString(dataRow.ItemArray[databaseNamefield]);
                dTNDatabase.DatabaseType = DataHelper.ParseInteger(dataRow.ItemArray[databaseTypefield], 0);
                dTNDatabase.DBPassword   = DataHelper.ParseString(dataRow.ItemArray[dBPasswordfield]);
                dTNDatabase.Exclude      = DataHelper.ParseInteger(dataRow.ItemArray[excludefield], 0);
                dTNDatabase.Path         = DataHelper.ParseString(dataRow.ItemArray[pathfield]);
                dTNDatabase.ProjectId    = DataHelper.ParseInteger(dataRow.ItemArray[projectIdfield], 0);
                dTNDatabase.Serializable = DataHelper.ParseBoolean(dataRow.ItemArray[serializablefield], false);
                dTNDatabase.ServerName   = DataHelper.ParseString(dataRow.ItemArray[serverNamefield]);
                dTNDatabase.UserId       = DataHelper.ParseString(dataRow.ItemArray[userIdfield]);
            }
            catch
            {
            }

            // return value
            return(dTNDatabase);
        }
Esempio n. 16
0
        /// <summary>
        /// This method adds a new database to the selected project.
        /// </summary>
        private void EditDatabase(DTNDatabase database)
        {
            // If the selected project exists
            if (this.SelectedProject != null)
            {
                // Create instance of Database SelectorForm
                DatabaseSelectorForm databaseForm = new DatabaseSelectorForm();

                // Set selected project
                databaseForm.DatabaseSelectorControl.Setup(this.SelectedProject, database);

                // Show Dialog
                databaseForm.ShowDialog();

                // if the user did not cancel
                if (!databaseForm.DatabaseSelectorControl.UserCancelled)
                {
                    // if the selected project exists and the SelectedDatabase exists on the databaseForm
                    if ((this.HasSelectedProject) && (databaseForm.DatabaseSelectorControl.SelectedDatabase != null))
                    {
                        // Get the index of this database
                        int index = this.SelectedProject.GetDatabaseIndex(databaseForm.DatabaseSelectorControl.SelectedDatabase.DatabaseId);

                        // if the index was found
                        if (index >= 0)
                        {
                            // remove this database
                            this.SelectedProject.Databases.RemoveAt(index);
                        }

                        // Add the selected database
                        this.SelectedProject.Databases.Add(databaseForm.DatabaseSelectorControl.SelectedDatabase);

                        // Display Database
                        this.DisplaySelectedProject();
                    }
                }
            }
        }
        /// <summary>
        /// This method prepares this control to be launched.
        /// </summary>
        /// <param name="selectedProjectArg"></param>
        internal void Setup(Project selectedProjectArg, DTNDatabase databaseArg)
        {
            // set selected project
            this.SelectedProject = selectedProjectArg;

            // set SelectedDatabase
            this.SelectedDatabase = databaseArg;

            // If this is not a new database (this is an edit)
            if (!this.SelectedDatabase.IsNew)
            {
                // if the form exists
                if (this.HasParentDatabaseSelectorForm)
                {
                    // Change the text
                    this.ParentDatabaseSelectorForm.Text = "Edit Database";
                }

                // Display the selected database
                this.DisplaySelectedDatabase();
            }
        }
        /// <summary>
        /// This method loads a collection of 'DTNDatabase' objects.
        /// from the dataTable.Rows object passed in.
        /// </summary>
        /// <param name='dataTable'>The 'DataTable.Rows' to load from.</param>
        /// <returns>A DTNDatabase Collection.</returns>
        public static List <DTNDatabase> LoadCollection(DataTable dataTable)
        {
            // Initial Value
            List <DTNDatabase> dTNDatabases = new List <DTNDatabase>();

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

                    // Add this object to collection
                    dTNDatabases.Add(dTNDatabase);
                }
            }
            catch
            {
            }

            // return value
            return(dTNDatabases);
        }
Esempio n. 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);
        }
Esempio n. 20
0
        /// <summary>
        /// This method creates an instance of a
        /// 'FetchAllDTNDatabasesUsersStoredProcedure' object and
        /// creates the sql parameter[] array needed
        /// to execute the procedure 'DTNDatabase_FetchAll'.
        /// </summary>
        /// <returns>An instance of a(n) 'FetchAllDTNDatabasesStoredProcedure' object.</returns>
        public new static FetchAllDTNDatabasesStoredProcedure CreateFetchAllDTNDatabasesStoredProcedure(DTNDatabase database)
        {
            // Initial value
            FetchAllDTNDatabasesStoredProcedure fetchAllDTNDatabasesStoredProcedure = new FetchAllDTNDatabasesStoredProcedure();

            // verify the database exists
            if ((database != null) && (database.ProjectId > 0))
            {
                // set the procedure name
                fetchAllDTNDatabasesStoredProcedure.ProcedureName = "DTNDatabase_FetchAllForProject";

                // create the parameters
                fetchAllDTNDatabasesStoredProcedure.Parameters = SqlParameterHelper.CreateSqlParameters("@ProjectId", database.ProjectId);
            }

            // return value
            return(fetchAllDTNDatabasesStoredProcedure);
        }
Esempio n. 21
0
        /// <summary>
        /// This method creates an instance of a
        /// 'FindDTNDatabaseStoredProcedure' object and
        /// creates the sql parameter[] array needed
        /// to execute the procedure 'DTNDatabase_Find'.
        /// </summary>
        /// <param name="dTNDatabase">The 'DTNDatabase' to use to
        /// get the primary key parameter.</param>
        /// <returns>An instance of an FetchUserStoredProcedure</returns>
        public static FindDTNDatabaseStoredProcedure CreateFindDTNDatabaseStoredProcedure(DTNDatabase dTNDatabase)
        {
            // Initial Value
            FindDTNDatabaseStoredProcedure findDTNDatabaseStoredProcedure = null;

            // verify dTNDatabase exists
            if (dTNDatabase != null)
            {
                // Instanciate findDTNDatabaseStoredProcedure
                findDTNDatabaseStoredProcedure = new FindDTNDatabaseStoredProcedure();

                // Now create parameters for this procedure
                findDTNDatabaseStoredProcedure.Parameters = CreatePrimaryKeyParameter(dTNDatabase);
            }

            // return value
            return(findDTNDatabaseStoredProcedure);
        }
Esempio n. 22
0
        /// <summary>
        /// This method creates an instance of an
        /// 'DeleteDTNDatabase'StoredProcedure' object and
        /// creates the sql parameter[] array needed
        /// to execute the procedure 'DTNDatabase_Delete'.
        /// </summary>
        /// <param name="dTNDatabase">The 'DTNDatabase' to Delete.</param>
        /// <returns>An instance of a 'DeleteDTNDatabaseStoredProcedure' object.</returns>
        public static DeleteDTNDatabaseStoredProcedure CreateDeleteDTNDatabaseStoredProcedure(DTNDatabase dTNDatabase)
        {
            // Initial Value
            DeleteDTNDatabaseStoredProcedure deleteDTNDatabaseStoredProcedure = new DeleteDTNDatabaseStoredProcedure();

            // Now Create Parameters For The DeleteProc
            deleteDTNDatabaseStoredProcedure.Parameters = CreatePrimaryKeyParameter(dTNDatabase);

            // return value
            return(deleteDTNDatabaseStoredProcedure);
        }
Esempio n. 23
0
        /// <summary>
        /// This method creates an instance of a
        /// 'FetchAllDTNDatabasesStoredProcedure' object and
        /// creates the sql parameter[] array needed
        /// to execute the procedure 'DTNDatabase_FetchAll'.
        /// </summary>
        /// <returns>An instance of a(n) 'FetchAllDTNDatabasesStoredProcedure' object.</returns>
        public static FetchAllDTNDatabasesStoredProcedure CreateFetchAllDTNDatabasesStoredProcedure(DTNDatabase dTNDatabase)
        {
            // Initial value
            FetchAllDTNDatabasesStoredProcedure fetchAllDTNDatabasesStoredProcedure = new FetchAllDTNDatabasesStoredProcedure();

            // return value
            return(fetchAllDTNDatabasesStoredProcedure);
        }
Esempio n. 24
0
        /// <summary>
        /// Converts a ObjectLibrary.Database
        /// SQLServer database to a DataJuggler.Net Database
        /// and reads the schema.
        /// </summary>
        /// <param name="databases"></param>
        /// <returns></returns>
        private Database ConvertSQLDatabase(DTNDatabase db, List <Enumeration> enumerations)
        {
            // Create sqlConnector
            SQLDatabaseConnector sqlConnector = new SQLDatabaseConnector();

            // if the tables are not loaded for the db
            if ((NullHelper.Exists(db)) && (!ListHelper.HasOneOrMoreItems(db.Tables)))
            {
                // Create a new instance of a 'Gateway' object.
                Gateway gateway = new Gateway();

                // load the tables
                db.Tables = gateway.LoadDTNTablesByProjectId(this.CurrentProject.ProjectId);
            }

            // if the DataManager does not exist
            if (NullHelper.IsNull(DataManager))
            {
                if (NullHelper.Exists(CurrentProject))
                {
                    // Don't know why this is still here, VB.Net was abandoned in 2006 or 2007
                    DataManager = new DataManager(CurrentProject.ProjectFolder, currentProject.ProjectName, DataManager.ClassOutputLanguage.CSharp);
                }
                else
                {
                    // exit
                    return(null);
                }
            }

            // Create Database
            DataJuggler.Net.Database database = new Database(this.DataManager);

            // Set Database Properties
            database.ClassFileName     = this.DataManager.ClassFileName;
            database.ClassName         = db.DatabaseName + ".cs";
            database.ConnectionString  = db.ConnectionString;
            database.Name              = db.DatabaseName;
            database.ParentDataManager = this.DataManager;
            database.Password          = db.DBPassword;
            database.Serializable      = true;
            database.StoredProcedures  = new List <StoredProcedure>();

            // set connection string
            sqlConnector.DatabaseConnection.ConnectionString = database.ConnectionString;

            // open database
            sqlConnector.DatabaseConnection.Open();

            // read database schema
            database = sqlConnector.LoadDatabaseSchema(database);

            // close this database
            sqlConnector.DatabaseConnection.Close();

            // if there are one or more tables
            if (ListHelper.HasOneOrMoreItems(database.Tables))
            {
                // iterate the collection of tables
                foreach (DataTable table in database.Tables)
                {
                    // if a DotNet5 project and EnableBlazorFeatures is true and BindingCallBack option is set to CreateBinding
                    if ((currentProject.TargetFramework != TargetFrameworkEnum.NetFramework) && (currentProject.EnableBlazorFeatures) && (currentProject.BindingCallbackOption == BindingCallbackOptionEnum.Create_Binding))
                    {
                        // Create the BindingCall back needs to be set to true to code generate the Callback.
                        table.CreateBindingCallback = true;
                    }

                    // if there are one or more fields
                    if (ListHelper.HasOneOrMoreItems(table.Fields, enumerations))
                    {
                        // iterate the fields
                        foreach (DataField field in table.Fields)
                        {
                            // now iterate te enumerations
                            foreach (Enumeration enumeration in enumerations)
                            {
                                // if this field is designated as an enumeration
                                if (TextHelper.IsEqual(field.FieldName, enumeration.FieldName))
                                {
                                    // set to true
                                    field.IsEnumeration = true;

                                    // Set this as enumeration
                                    field.DataType = DataManager.DataTypeEnum.Enumeration;

                                    // Set the EnumerationName
                                    field.EnumDataTypeName = enumeration.EnumerationName;
                                }
                            }
                        }
                    }
                }
            }

            // return value
            return(database);
        }
Esempio n. 25
0
        /// <summary>
        /// This method creates an instance of an
        /// 'UpdateDTNDatabaseStoredProcedure' object and
        /// creates the sql parameter[] array needed
        /// to execute the procedure 'DTNDatabase_Update'.
        /// </summary>
        /// <param name="dTNDatabase"The 'DTNDatabase' object to update</param>
        /// <returns>An instance of a 'UpdateDTNDatabaseStoredProcedure</returns>
        public static UpdateDTNDatabaseStoredProcedure CreateUpdateDTNDatabaseStoredProcedure(DTNDatabase dTNDatabase)
        {
            // Initial Value
            UpdateDTNDatabaseStoredProcedure updateDTNDatabaseStoredProcedure = null;

            // verify dTNDatabase exists
            if (dTNDatabase != null)
            {
                // Instanciate updateDTNDatabaseStoredProcedure
                updateDTNDatabaseStoredProcedure = new UpdateDTNDatabaseStoredProcedure();

                // Now create parameters for this procedure
                updateDTNDatabaseStoredProcedure.Parameters = CreateUpdateParameters(dTNDatabase);
            }

            // return value
            return(updateDTNDatabaseStoredProcedure);
        }
Esempio n. 26
0
        /// <summary>
        /// This method creates the sql Parameters[] needed for
        /// update an existing dTNDatabase.
        /// </summary>
        /// <param name="dTNDatabase">The 'DTNDatabase' to update.</param>
        /// <returns></returns>
        internal static SqlParameter[] CreateUpdateParameters(DTNDatabase dTNDatabase)
        {
            // Initial Values
            SqlParameter[] parameters = new SqlParameter[12];
            SqlParameter   param      = null;

            // verify dTNDatabaseexists
            if (dTNDatabase != null)
            {
                // Create parameter for [AuthenticationType]
                param = new SqlParameter("@AuthenticationType", dTNDatabase.AuthenticationType);

                // set parameters[0]
                parameters[0] = param;

                // Create parameter for [ConnectionString]
                param = new SqlParameter("@ConnectionString", dTNDatabase.ConnectionString);

                // set parameters[1]
                parameters[1] = param;

                // Create parameter for [DatabaseName]
                param = new SqlParameter("@DatabaseName", dTNDatabase.DatabaseName);

                // set parameters[2]
                parameters[2] = param;

                // Create parameter for [DatabaseType]
                param = new SqlParameter("@DatabaseType", dTNDatabase.DatabaseType);

                // set parameters[3]
                parameters[3] = param;

                // Create parameter for [DBPassword]
                param = new SqlParameter("@DBPassword", dTNDatabase.DBPassword);

                // set parameters[4]
                parameters[4] = param;

                // Create parameter for [Exclude]
                param = new SqlParameter("@Exclude", dTNDatabase.Exclude);

                // set parameters[5]
                parameters[5] = param;

                // Create parameter for [Path]
                param = new SqlParameter("@Path", dTNDatabase.Path);

                // set parameters[6]
                parameters[6] = param;

                // Create parameter for [ProjectId]
                param = new SqlParameter("@ProjectId", dTNDatabase.ProjectId);

                // set parameters[7]
                parameters[7] = param;

                // Create parameter for [Serializable]
                param = new SqlParameter("@Serializable", dTNDatabase.Serializable);

                // set parameters[8]
                parameters[8] = param;

                // Create parameter for [ServerName]
                param = new SqlParameter("@ServerName", dTNDatabase.ServerName);

                // set parameters[9]
                parameters[9] = param;

                // Create parameter for [UserId]
                param = new SqlParameter("@UserId", dTNDatabase.UserId);

                // set parameters[10]
                parameters[10] = param;

                // Create parameter for [DatabaseId]
                param          = new SqlParameter("@DatabaseId", dTNDatabase.DatabaseId);
                parameters[11] = param;
            }

            // return value
            return(parameters);
        }
Esempio n. 27
0
        /// <summary>
        /// This method creates an instance of an
        /// 'InsertDTNDatabaseStoredProcedure' object and
        /// creates the sql parameter[] array needed
        /// to execute the procedure 'DTNDatabase_Insert'.
        /// </summary>
        /// <param name="dTNDatabase"The 'DTNDatabase' object to insert</param>
        /// <returns>An instance of a 'InsertDTNDatabaseStoredProcedure' object.</returns>
        public static InsertDTNDatabaseStoredProcedure CreateInsertDTNDatabaseStoredProcedure(DTNDatabase dTNDatabase)
        {
            // Initial Value
            InsertDTNDatabaseStoredProcedure insertDTNDatabaseStoredProcedure = null;

            // verify dTNDatabase exists
            if (dTNDatabase != null)
            {
                // Instanciate insertDTNDatabaseStoredProcedure
                insertDTNDatabaseStoredProcedure = new InsertDTNDatabaseStoredProcedure();

                // Now create parameters for this procedure
                insertDTNDatabaseStoredProcedure.Parameters = CreateInsertParameters(dTNDatabase);
            }

            // return value
            return(insertDTNDatabaseStoredProcedure);
        }
Esempio n. 28
0
        /// <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;
                }
            }
        }