-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c5743d
commit a6e5371
Showing
26 changed files
with
1,105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bin/ | ||
.vs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Application x:Class="SQLBuilder.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:SQLBuilder" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace SQLBuilder | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Window x:Class="SQLBuilder.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:SQLBuilder" | ||
mc:Ignorable="d" | ||
Title="SQL Builder" Height="450" Width="800"> | ||
<Grid> | ||
<TextBox x:Name="txt_querybox" HorizontalAlignment="Left" Height="327" Margin="309,51,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="450" VerticalScrollBarVisibility="Visible"/> | ||
<Label Content="SQL Query" HorizontalAlignment="Left" Margin="309,24,0,0" VerticalAlignment="Top"/> | ||
<Label Content="MDF Location" HorizontalAlignment="Left" Margin="57,93,0,0" VerticalAlignment="Top"/> | ||
<Label Content="LDF Location" HorizontalAlignment="Left" Margin="57,160,0,0" VerticalAlignment="Top"/> | ||
<Label Content="File Prefix" HorizontalAlignment="Left" Margin="57,24,0,0" VerticalAlignment="Top"/> | ||
<TextBox x:Name="txt_prefix" HorizontalAlignment="Left" Height="23" Margin="57,55,0,0" Text="" VerticalAlignment="Top" Width="120"/> | ||
<TextBox x:Name="txt_mdfloc" HorizontalAlignment="Left" Height="23" Margin="57,124,0,0" Text="" VerticalAlignment="Top" Width="120" AutomationProperties.IsRequiredForForm="True"/> | ||
<TextBox x:Name="txt_ldfloc" HorizontalAlignment="Left" Height="23" Margin="57,191,0,0" Text="" VerticalAlignment="Top" Width="120" AutomationProperties.IsRequiredForForm="True"/> | ||
<Button Content="Browse..." HorizontalAlignment="Left" Margin="187,124,0,0" VerticalAlignment="Top" Width="87" Height="23" Click="ChooseFolder_mdf"/> | ||
<Button Content="Browse..." HorizontalAlignment="Left" Margin="187,191,0,0" VerticalAlignment="Top" Width="87" Height="23" Click="ChooseFolder_ldf"/> | ||
<Button Content="Submit" HorizontalAlignment="Left" Margin="44,351,0,0" VerticalAlignment="Top" Width="102" Height="27" Click="Submit_Click"/> | ||
<Button Content="Export" HorizontalAlignment="Left" Margin="167,351,0,0" VerticalAlignment="Top" Width="102" Height="27" Click="Export_Query"/> | ||
|
||
|
||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Windows; | ||
using System.Windows.Forms; | ||
using System.IO; | ||
|
||
|
||
namespace SQLBuilder | ||
{ | ||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
// Icon by www.flaticon.com/authors/smashicons | ||
|
||
private void ChooseFolder_mdf(object sender, RoutedEventArgs e) | ||
{ | ||
using (var folderDialog = new FolderBrowserDialog()) | ||
{ | ||
if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) | ||
{ | ||
txt_mdfloc.Text = folderDialog.SelectedPath; | ||
// folderDialog.SelectedPath -- your result | ||
} | ||
} | ||
} | ||
|
||
private void ChooseFolder_ldf(object sender, RoutedEventArgs e) | ||
{ | ||
using (var folderDialog = new FolderBrowserDialog()) | ||
{ | ||
if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) | ||
{ | ||
txt_ldfloc.Text = folderDialog.SelectedPath; | ||
// folderDialog.SelectedPath -- your result | ||
} | ||
} | ||
} | ||
|
||
private void Submit_Click(object sender, RoutedEventArgs e) | ||
{ | ||
// Process needed inputs | ||
if (String.IsNullOrWhiteSpace(txt_mdfloc.Text)) | ||
{ | ||
System.Windows.Forms.MessageBox.Show("MDF file location cannot be blank."); | ||
return; | ||
} | ||
|
||
if (String.IsNullOrWhiteSpace(txt_ldfloc.Text)) | ||
{ | ||
System.Windows.Forms.MessageBox.Show("LDF file location cannot be blank."); | ||
return; | ||
} | ||
|
||
// Clear output box to allow for new content | ||
txt_querybox.Text = ""; | ||
|
||
// create Tab character | ||
char tab = '\u0009'; | ||
|
||
// Get all MDF files from the input field | ||
string[] mdf_files; | ||
mdf_files = Directory.GetFiles(txt_mdfloc.Text, $"*{txt_prefix.Text}*.mdf", SearchOption.TopDirectoryOnly); | ||
|
||
// Get all LDF files from the input field | ||
string[] ldf_files; | ||
ldf_files = Directory.GetFiles(txt_ldfloc.Text, $"*{txt_prefix.Text}*.ldf", SearchOption.TopDirectoryOnly); | ||
|
||
// Zip arrays together | ||
var filenames = mdf_files.Zip(ldf_files, (m, l) => new { MDF = m, LDF = l }); | ||
|
||
foreach (var filename in filenames) | ||
{ | ||
// Parse base name of file for our database name | ||
string DBName = System.IO.Path.GetFileNameWithoutExtension(filename.MDF); | ||
|
||
// Update our text box by adding to the content | ||
// Accessing MDF file path with file.MDF | ||
// Accessing LDF file path with file.LDF | ||
txt_querybox.Text += $@"CREATE DATABASE {DBName}{Environment.NewLine}" | ||
+ $@"{tab}ON (FILENAME = '{filename.MDF}'),{Environment.NewLine}" | ||
+ $@"{tab}(FILENAME = '{filename.LDF}'){Environment.NewLine}" | ||
+ $@"{tab}FOR ATTACH;" | ||
+ Environment.NewLine + Environment.NewLine; | ||
} | ||
} | ||
|
||
private void Export_Query(object sender, RoutedEventArgs e) | ||
{ | ||
string cwd = Directory.GetCurrentDirectory(); | ||
string filename = null; | ||
|
||
if (String.IsNullOrEmpty(txt_prefix.Text)) | ||
{ | ||
filename = $@"{cwd}\MassAttach.sql"; | ||
} | ||
else | ||
{ | ||
filename = $@"{cwd}\{txt_prefix.Text}_MassAttach.sql"; | ||
} | ||
|
||
try | ||
{ | ||
File.WriteAllText(filename, txt_querybox.Text); | ||
System.Windows.Forms.MessageBox.Show($@"File saved to {filename}"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
System.Windows.Forms.MessageBox.Show($@"Problem saving to {filename}" + Environment.NewLine + ex); | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Reflection; | ||
using System.Resources; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using System.Windows; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("SQLBuilder")] | ||
[assembly: AssemblyDescription("Simple Mass Attach Script for SQL Database Files")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Clayton Errington")] | ||
[assembly: AssemblyProduct("SQLBuilder")] | ||
[assembly: AssemblyCopyright("Copyright © 2020")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
//In order to begin building localizable applications, set | ||
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file | ||
//inside a <PropertyGroup>. For example, if you are using US english | ||
//in your source files, set the <UICulture> to en-US. Then uncomment | ||
//the NeutralResourceLanguage attribute below. Update the "en-US" in | ||
//the line below to match the UICulture setting in the project file. | ||
|
||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] | ||
|
||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] | ||
|
||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.