internal static string DropForeignKey(string integrityDropString)
        {
            IScripting scriptor = Scripting.CreateClass();

            string[] keySplit = integrityDropString.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries);

            return(scripting.DropForeignKey(keySplit[0], keySplit[1]));
        }
        private void BildProgress_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                DataAccess data = new DataAccess(Connections.DatabaseModel);

                foreach (string contraint in Integrity.DropRelations)
                {
                    data.ExecuteNonQuery(Scripting.DropForeignKey(contraint));
                }

                TableModel[] tablesArray = (TableModel[])e.Argument;

                for (int x = 0; x < tablesArray.Length; x++)
                {
                    TableModel table = tablesArray[x];

                    this.buildWorker.ReportProgress((x + 1), $"Executing: {table.TableName}");

                    data.ExecuteNonQuery(Scripting.ScriptTableCreate(table));
                }

                for (int x = 0; x < tablesArray.Length; x++)
                {
                    TableModel table = tablesArray[x];

                    this.buildWorker.ReportProgress((x + 1), $"Relations: {table.TableName}");

                    string sqlQuery = Scripting.BuildForeignKey(table);

                    if (sqlQuery.IsNullEmptyOrWhiteSpace())
                    {
                        continue;
                    }

                    data.ExecuteNonQuery(sqlQuery);
                }
            }
            catch
            {
                throw;
            }
        }
        internal static string BuildForeignKey(TableModel table)
        {
            IScripting scriptor = Scripting.CreateClass();

            return(scriptor.BuildForeignKey(table));
        }
        internal static string ScriptTableCreate(TableModel table)
        {
            IScripting scriptor = Scripting.CreateClass();

            return(scriptor.ScriptTableCreate(table));
        }
        private void ScriptProgress_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                StringBuilder result = new StringBuilder();

                foreach (string contraint in Integrity.DropRelations)
                {
                    result.Append(Scripting.DropForeignKey(contraint));

                    result.AppendLine();
                }

                TableModel[] tablesArray = (TableModel[])e.Argument;

                for (int x = 0; x < tablesArray.Length; x++)
                {
                    TableModel table = tablesArray[x];

                    this.buildWorker.ReportProgress((x + 1), $"Executing: {table.TableName}");

                    result.AppendLine(Scripting.ScriptTableCreate(table));

                    result.AppendLine();
                }

                for (int x = 0; x < tablesArray.Length; x++)
                {
                    TableModel table = tablesArray[x];

                    this.buildWorker.ReportProgress((x + 1), $"Relations: {table.TableName}");

                    string sqlQuery = Scripting.BuildForeignKey(table);

                    if (sqlQuery.IsNullEmptyOrWhiteSpace())
                    {
                        continue;
                    }

                    result.AppendLine(sqlQuery);

                    result.AppendLine();
                }

                string outPath = Path.Combine(Paths.KnownFolder(KnownFolders.KnownFolder.Downloads), $"{Connections.DatabaseModel.DatabaseName}.sql");

                int outIndex = 1;

                while (File.Exists(outPath))
                {
                    outPath = Path.Combine(Paths.KnownFolder(KnownFolders.KnownFolder.Downloads), $"{Connections.DatabaseModel.DatabaseName} ({outIndex}).sql");

                    ++outIndex;
                }

                File.WriteAllText(outPath, result.ToString());

                Process.Start(Paths.KnownFolder(KnownFolders.KnownFolder.Downloads));
            }
            catch
            {
                throw;
            }
        }