Пример #1
0
        // METHOD HEADER COMMENT -------------------------------------------------------------------------------

        /**
         *   \fn            Insert
         *   \brief         this method will be able to insert into any table that using the corresponding
         *                  ParentTable
         *   \param[in]     ParentTable input
         *   \param[out]    none
         *   \return        bool
         * ---------------------------------------------------------------------------------------------------- */
        public static bool Insert(ParentTable input)
        {
            try
            {
                //get the insert statement
                string query = input.GetInsertStatment();

                //create command and assign the query and connection from the constructor
                MySqlCommand cmd = new MySqlCommand(query, connection);

                //Execute command
                if (cmd.ExecuteNonQuery() > 0)
                {
                    TMSBackup.WriteQueryToCurrentFile(new TMSBackupQuery(query));
                }

                TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "Insert" + " | " + "Confirmation" + " | " + "Data inserted into SQL database" + " | ");
                return(true);
            }
            catch (Exception e)
            {
                //logit
                TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "Insert" + " | " + e.GetType().ToString() + " | " + e.Message + " | ");
                return(false);
            }
        }
Пример #2
0
        static public bool RecoverRestorePoint(TMSBackup b)
        {
            bool readSuccess = true;

            try
            {
                FileInfo restoreFile = new FileInfo(b.filePath);
                if (restoreFile.Exists == true)
                {
                    List <string> AllTableName = new List <string>();

                    // Reset database
                    string query = "DROP DATABASE IF EXISTS duane_test; CREATE DATABASE duane_test;";
                    SQL.GenericFunction(query);

                    // Run table builder string
                    SQL.GenericFunction(BuildTables.tableBuilder);

                    // Run CSV!

                    // Run all queries since the database started
                    string restoreQueries = System.IO.File.ReadAllText(b.filePath);
                    SQL.GenericFunction(restoreQueries);
                }
            }
            /// If an exception is thrown here, create a log for it.
            catch (Exception e)
            {
                TMSLogger.LogIt(" | " + "AdminClasses.cs" + " | " + "TMSBackup" + " | " + "RecoverRestorePoint" + " | " + e.GetType().ToString() + " | " + e.Message + " | ");
                readSuccess = false;
            }

            return(readSuccess);
        }
Пример #3
0
        // METHOD HEADER COMMENT -------------------------------------------------------------------------------

        /**
         *   \fn          GenericFunction
         *   \brief       This method will be called if for a generic query
         *   \param[in]   string Query
         *   \param[out]  none
         *   \return      bool
         * ---------------------------------------------------------------------------------------------------- */
        public static bool GenericFunction(string Query)
        {
            try
            {
                //create command and assign the query and connection from the constructor
                MySqlCommand cmd = new MySqlCommand(Query, connection);

                //Execute command
                if (cmd.ExecuteNonQuery() > 0)
                {
                    TMSBackup.WriteQueryToCurrentFile(new TMSBackupQuery(Query));
                }

                TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "GenericFunction" + " | " + "Confirmation" + " | " + "Query executed successfully" + " | ");
                return(true);
            }
            catch (Exception e)
            {
                TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "GenericFunction" + " | " + e.GetType().ToString() + " | " + e.Message + " | ");
                return(false);
            }
        }