diff --git a/DataScriptWriter.csproj b/DataScriptWriter.csproj
index 5d5c6ef..e19207a 100644
--- a/DataScriptWriter.csproj
+++ b/DataScriptWriter.csproj
@@ -72,6 +72,9 @@
packages\XtraEditor.Controls.18.2.4\lib\net45\DevExpress.XtraTreeList.v18.2.dll
+
+ packages\DotNetZip.1.15.0\lib\net40\DotNetZip.dll
+
packages\Microsoft.SqlServer.Types.14.0.1016.290\lib\net40\Microsoft.SqlServer.Types.dll
diff --git a/frmMain.cs b/frmMain.cs
index ce5832b..4779563 100644
--- a/frmMain.cs
+++ b/frmMain.cs
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Data;
+using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Diagnostics;
+using Ionic.Zip;
namespace DataScriptWriter
{
@@ -23,7 +25,10 @@ public frmMain()
Global.AppName = String.Format("{0} - ver. {1}", fileVersionInfo.ProductName, fileVersionInfo.ProductVersion);
this.Text = Global.AppName;
- _OutputFolder = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
+ string strTempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(strTempPath);
+
+ _OutputFolder = strTempPath;
}
private void btnConnect_Click(object sender, EventArgs e)
@@ -47,6 +52,11 @@ private void Connect()
private void bbiExit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
+ try
+ {
+ Directory.Delete(_OutputFolder, true);
+ }
+ catch { }
this.Close();
}
@@ -65,15 +75,31 @@ private void gridView1_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.
private void bbiScript_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
int cnt = 0;
- foreach (DataRowView item in _gen.SelectedItemView)
+ if (_gen == null || _gen.SelectedItemView == null)
{
- ScriptObject so = new ScriptObject(item);
- barStaticItem1.Caption = "Scripting: " + so.FullQuoted;
- this.Refresh();
- _gen.GenerateForTable(so);
- cnt++;
+ barStaticItem1.Caption = "Incomplete connection to script";
+ }
+ else
+ {
+ foreach (DataRowView item in _gen.SelectedItemView)
+ {
+ ScriptObject so = new ScriptObject(item);
+ barStaticItem1.Caption = "Scripting: " + so.FullQuoted;
+ this.Refresh();
+ _gen.GenerateForTable(so);
+ cnt++;
+ }
+ barStaticItem1.Caption = String.Format("Done. {0} tables were scripted.", cnt);
+
+ string[] arrSqlFiles = Directory.GetFiles(_OutputFolder, "*.sql");
+ string strZipPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "DataScriptWriter");
+ Directory.CreateDirectory(strZipPath);
+
+ ZipFile zipFile = new ZipFile(_OutputFolder);
+ zipFile.AddFiles(arrSqlFiles, "/");
+ zipFile.Save(Path.Combine(strZipPath, string.Format("Export_{0}" + ".zip",DateTime.Now.ToString("yyyyMMdd HHmmss"))));
+ zipFile = null;
}
- barStaticItem1.Caption = String.Format("Done. {0} tables were scripted.", cnt);
}
private void gridControl1_DoubleClick(object sender, EventArgs e)
diff --git a/packages.config b/packages.config
index 9391937..e16e2e9 100644
--- a/packages.config
+++ b/packages.config
@@ -1,5 +1,6 @@
+
\ No newline at end of file