├── .gitignore ├── App.config ├── CAMOsoft └── CAMOsoft.DbUtils │ ├── Asserts.cs │ ├── CAMOsoft.DbUtils.csproj │ ├── DbSession.cs │ ├── MsSqlCmd.cs │ ├── MsSqlSession.cs │ ├── SqlServerTypes │ ├── Loader.cs │ └── readme.htm │ └── packages.config ├── ChangesLog.txt ├── ConnectDbForm.cs ├── ConnectDbForm.designer.cs ├── ConnectDbForm.resx ├── DataScriptWriter.csproj ├── DataScriptWriter.sln ├── Global.cs ├── OUTPUT ├── Application.TransactionTypes.sql ├── Person.AddressType_INSERT.sql ├── Person.AddressType_MERGE.sql ├── Person.ContactType.sql ├── Person.PhoneNumberType.sql ├── Person.PhoneNumberType_INSERT.sql ├── Person.PhoneNumberType_MERGE.sql ├── Person.PhoneNumberType_MERGE_NEW_ONLY.sql └── Person.PhoneNumberType_MERGE_without_DELETE.sql ├── Program.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs ├── Settings.settings └── licenses.licx ├── README.md ├── RequiredDLL ├── x64 │ ├── SqlServerSpatial140.dll │ └── msvcr120.dll └── x86 │ ├── SqlServerSpatial140.dll │ └── msvcr120.dll ├── Resources ├── data_backup.ico ├── if_Archive_box_data_file_storage_1886362.ico ├── if_connect_established_1721.png ├── if_exit_6035.png └── if_script_lightning_36406.png ├── ScriptObject.cs ├── ScriptWriter.cs ├── SqlServerTypes ├── Loader.cs └── readme.htm ├── frmMain.Designer.cs ├── frmMain.cs ├── frmMain.resx ├── frmNoteForm.Designer.cs ├── frmNoteForm.cs ├── frmNoteForm.resx ├── images └── data-script-writer-selecting.png └── packages.config /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /CAMOsoft/CAMOsoft.DbUtils/Asserts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace CAMOsoft.DbUtils 6 | { 7 | public static class Asserts 8 | { 9 | 10 | public static void Assert(bool pCond, string pMessage) 11 | { 12 | if (!pCond) 13 | if (pMessage == null) 14 | throw new Exception("Assertion failed"); 15 | else 16 | throw new Exception("Assertion failed: " + pMessage); 17 | } 18 | 19 | public static void Assert(bool pCond, Exception pThrowEx) 20 | { 21 | if (!pCond) 22 | if (pThrowEx == null) 23 | throw new Exception("Assertion failed"); 24 | else 25 | throw pThrowEx; 26 | } 27 | 28 | public static void Assert(bool pCond) 29 | { 30 | Assert(pCond, String.Empty); 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CAMOsoft/CAMOsoft.DbUtils/CAMOsoft.DbUtils.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {3E8FF80A-749B-47EC-941D-1A98EFF4540C} 9 | Library 10 | Properties 11 | CAMOsoft.DbUtils 12 | CAMOsoft.DbUtils 13 | v4.7.2 14 | 512 15 | 16 | 17 | 18 | 19 | 3.5 20 | 21 | publish\ 22 | true 23 | Disk 24 | false 25 | Foreground 26 | 7 27 | Days 28 | false 29 | false 30 | true 31 | 0 32 | 1.0.0.%2a 33 | false 34 | false 35 | true 36 | SAK 37 | SAK 38 | SAK 39 | SAK 40 | 41 | 42 | 43 | true 44 | full 45 | false 46 | bin\Debug\ 47 | DEBUG;TRACE 48 | prompt 49 | 4 50 | AllRules.ruleset 51 | false 52 | 53 | 54 | pdbonly 55 | true 56 | bin\Release\ 57 | TRACE 58 | prompt 59 | 4 60 | AllRules.ruleset 61 | false 62 | 63 | 64 | x86 65 | bin\x86\Debug\ 66 | AllRules.ruleset 67 | false 68 | 69 | 70 | x86 71 | bin\x86\Release\ 72 | AllRules.ruleset 73 | false 74 | 75 | 76 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | ..\..\packages\Microsoft.SqlServer.Types.14.0.1016.290\lib\net40\Microsoft.SqlServer.Types.dll 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | False 102 | .NET Framework 3.5 SP1 Client Profile 103 | false 104 | 105 | 106 | False 107 | .NET Framework 3.5 SP1 108 | true 109 | 110 | 111 | False 112 | Windows Installer 3.1 113 | true 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /CAMOsoft/CAMOsoft.DbUtils/DbSession.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Data; 5 | using System.Data.Common; 6 | using System.Collections; 7 | using System.Data.SqlClient; 8 | 9 | namespace CAMOsoft.DbUtils 10 | { 11 | public abstract class DbSession 12 | { 13 | 14 | #region *** members *** 15 | 16 | private bool m_Logged; 17 | protected bool m_PrimaryKeyRequest = true; 18 | protected int m_CommandTimeoutDef = 90; 19 | protected int m_CommandTimeout = 90; 20 | protected string m_DbServer; 21 | protected string m_DbName; 22 | protected string m_DbUserName; 23 | protected string m_DbUserPass; 24 | protected bool m_Pooling = true; 25 | protected int m_MaxPoolingSize = 100; 26 | public Exception LoginException = null; 27 | 28 | private DbConnection m_Connection; 29 | private DbTransaction m_Trans; 30 | private bool m_MultiTransactionMode = false; 31 | private int m_TransactionCount = 0; 32 | 33 | private int m_BatchSize = 1; 34 | private string m_CurrentUpdating = ""; 35 | 36 | #endregion 37 | 38 | #region *** SYSTEM *** 39 | 40 | public DbSession() 41 | { 42 | } 43 | 44 | public DbSession(bool pooling) 45 | { 46 | m_Pooling = pooling; 47 | } 48 | 49 | public DbSession(string pConnectionString) 50 | { 51 | Connect(pConnectionString); 52 | PostInit(); 53 | } 54 | 55 | protected void Login(string pDbServer, string pDbUserName, string pDbUserPass, string pDbName) 56 | { 57 | m_DbServer = pDbServer; 58 | m_DbName = pDbName; 59 | m_DbUserName = pDbUserName; 60 | m_DbUserPass = pDbUserPass; 61 | Connect(); 62 | PostInit(); 63 | } 64 | 65 | protected void Login(string pDbServer, string pDbUserName, string pDbUserPass, string pDbName, bool pPooling) 66 | { 67 | m_DbServer = pDbServer; 68 | m_DbName = pDbName; 69 | m_DbUserName = pDbUserName; 70 | m_DbUserPass = pDbUserPass; 71 | m_Pooling = pPooling; 72 | Connect(); 73 | PostInit(); 74 | } 75 | 76 | protected virtual void PostInit() 77 | { 78 | 79 | } 80 | 81 | #endregion 82 | 83 | #region *** ABSTRACT *** 84 | 85 | public abstract DbDataAdapter CreateDataAdapter(); 86 | public abstract DbCommand CreateCommand(); 87 | public abstract DbCommandBuilder CreateCommandBuilder(DbDataAdapter pDa); 88 | public abstract string GetConnectionString(); 89 | public abstract DbConnection CreateConnection(string pConnectionString); 90 | 91 | #endregion 92 | 93 | #region *** SYSTEM PUBLIC - BEGIN/END *** 94 | 95 | public void CloseConnection() 96 | { 97 | if (m_Connection.State == ConnectionState.Open) 98 | m_Connection.Close(); 99 | } 100 | 101 | #endregion 102 | 103 | #region *** PUBLIC SELECT *** 104 | 105 | public DataRow SelectRow(String pSql) 106 | { 107 | DataTable MyTable = SelectTable(pSql, "Table0"); 108 | if (MyTable.Rows.Count > 0) 109 | return MyTable.Rows[0]; 110 | else 111 | return null; 112 | } 113 | 114 | public object SelectValue(string pSql) 115 | { 116 | DbCommand MyCommand; 117 | MyCommand = CreateCommand(pSql); 118 | return MyCommand.ExecuteScalar(); 119 | } 120 | 121 | public Guid SelectValueGuid(string pSql) 122 | { 123 | return new Guid(SelectValue(pSql).ToString()); 124 | } 125 | 126 | public int SelectValueInt(string pSql) 127 | { 128 | return int.Parse(SelectValue(pSql).ToString()); 129 | } 130 | 131 | public long SelectValueLong(string pSql) 132 | { 133 | return long.Parse(SelectValue(pSql).ToString()); 134 | } 135 | 136 | public DbDataAdapter CreateDataAdapter(string pSelectCmdSql) 137 | { 138 | DbDataAdapter MyDa = CreateDataAdapter(); 139 | MyDa.SelectCommand = CreateCommand(pSelectCmdSql); 140 | return MyDa; 141 | } 142 | 143 | public DbDataAdapter CreateDataAdapter(DataSet pDs, String pTableName) 144 | { 145 | DbDataAdapter MyDa = CreateDataAdapter(); 146 | String MyColumns = ""; 147 | 148 | foreach (DataColumn MyCol in pDs.Tables[pTableName].Columns) 149 | MyColumns += "," + QuotedName(MyCol.ColumnName); 150 | if (MyColumns.Length > 0) MyColumns = MyColumns.Remove(0, 1); 151 | MyDa.SelectCommand = CreateCommand("SELECT " + MyColumns + " FROM " + QuotedName(pTableName) + " WHERE 0=1"); 152 | return MyDa; 153 | } 154 | 155 | protected DataTable SelectData(string pSql, string pName, bool pWithSchema) 156 | { 157 | DbDataAdapter MyDA = CreateDataAdapter(); 158 | DataSet MyDs = new DataSet(); 159 | MyDA.SelectCommand = CreateCommand(pSql); 160 | if (pWithSchema) 161 | MyDA.FillSchema(MyDs, SchemaType.Source, pName); 162 | MyDA.Fill(MyDs, pName); 163 | DataTable MyTable = MyDs.Tables[0]; 164 | MyDs.Tables.Remove(MyTable); 165 | return MyTable; 166 | } 167 | 168 | public DataTable SelectTable(string pSql, string pTableName) 169 | { 170 | return SelectData(pSql, pTableName, true); 171 | } 172 | 173 | public DataTable SelectView(string pSql, string pViewName) 174 | { 175 | return SelectData(pSql, pViewName, false); 176 | } 177 | 178 | public void SelectDsData(DataSet pDs, string pSql, string pTableName, bool pWithSchema) 179 | { 180 | DbDataAdapter MyDA = CreateDataAdapter(); 181 | MyDA.SelectCommand = CreateCommand(pSql); 182 | if (pWithSchema) 183 | MyDA.FillSchema(pDs, SchemaType.Source, pTableName); 184 | MyDA.Fill(pDs, pTableName); 185 | } 186 | 187 | public void SelectDs(DataSet pDs, string pSql, string pTableName) 188 | { 189 | SelectDsData(pDs, pSql, pTableName, true); 190 | } 191 | 192 | public void SelectDsData(DataSet pDs, string pSql, string pTableName, bool pWithSchema, int pStartRecord, int pMaxRecord) 193 | { 194 | DbDataAdapter MyDA = CreateDataAdapter(); 195 | MyDA.SelectCommand = CreateCommand(pSql); 196 | if (pWithSchema) 197 | MyDA.FillSchema(pDs, SchemaType.Source, pTableName); 198 | MyDA.Fill(pDs, pStartRecord, pMaxRecord, pTableName); 199 | } 200 | 201 | public void SelectDs(DataSet pDs, string pSql, string pTableName, int pStartRecord, int pMaxRecord) 202 | { 203 | SelectDsData(pDs, pSql, pTableName, true, pStartRecord, pMaxRecord); 204 | } 205 | 206 | public void SelectDsView(DataSet pDs, string pSql, string pViewName) 207 | { 208 | DbDataAdapter MyDA = CreateDataAdapter(); 209 | MyDA.SelectCommand = CreateCommand(pSql); 210 | MyDA.Fill(pDs, pViewName); 211 | } 212 | 213 | public void SelectDsView(DataSet pDs, string pSql, string pViewName, int pStartRecord, int pMaxRecord) 214 | { 215 | DbDataAdapter MyDA = CreateDataAdapter(); 216 | MyDA.SelectCommand = CreateCommand(pSql); 217 | MyDA.Fill(pDs, pStartRecord, pMaxRecord, pViewName); 218 | } 219 | 220 | public void SelectSchema(DataSet pDs, string pTableName) 221 | { 222 | SelectSchema(pDs, "SELECT * FROM " + QuotedName(pTableName) + " WHERE 0 = 1", pTableName); 223 | } 224 | 225 | public void SelectSchema(DataSet pDs, string pSql, String pTableName) 226 | { 227 | DbDataAdapter MyDa = CreateDataAdapter(); 228 | MyDa.SelectCommand = CreateCommand(pSql); 229 | MyDa.FillSchema(pDs, SchemaType.Source, pTableName); 230 | } 231 | 232 | #endregion 233 | 234 | #region *** COMMANDS *** 235 | 236 | public DbCommand CreateCommand(string pSql) 237 | { 238 | DbCommand MyCmd = CreateCommand(); 239 | MyCmd.CommandText = pSql; 240 | MyCmd.Connection = m_Connection; 241 | MyCmd.Transaction = m_Trans; 242 | MyCmd.CommandTimeout = m_CommandTimeout; 243 | return MyCmd; 244 | } 245 | 246 | public int Execute(string pSql) 247 | { 248 | DbCommand MyCommand = CreateCommand(pSql); 249 | return MyCommand.ExecuteNonQuery(); 250 | } 251 | 252 | public int ExecuteNoTimeout(string pSql) 253 | { 254 | DbCommand MyCommand = CreateCommand(pSql); 255 | MyCommand.CommandTimeout = 0; 256 | return MyCommand.ExecuteNonQuery(); 257 | } 258 | 259 | #endregion 260 | 261 | #region *** UPDATE / SAVE *** 262 | 263 | public void Update(DataSet pDs, string pTableName) 264 | { 265 | Update(pDs, pTableName, 1); 266 | } 267 | 268 | public void Update(DataSet pDs, string pTableName, int pBatchSize) 269 | { 270 | if (pDs.Tables[pTableName] == null) 271 | throw new Exception("This table don't exist!"); 272 | else 273 | { 274 | List MyTableOrder = new List(); 275 | MyTableOrder.Add(pTableName); 276 | Update(pDs, MyTableOrder, pBatchSize); 277 | } 278 | } 279 | 280 | public void Update(DataSet pDs, string[] pTableOrder) 281 | { 282 | List MyTableOrder = new List(pTableOrder); 283 | Update(pDs, MyTableOrder, 1); 284 | } 285 | 286 | private void Update(DataSet pDs, List pTableOrder, int pBatchSize) 287 | { 288 | m_CurrentUpdating = ""; 289 | m_BatchSize = pBatchSize; 290 | pTableOrder.Reverse(); 291 | PerformDelete(pDs, pTableOrder); 292 | pTableOrder.Reverse(); 293 | PerformInsert(pDs, pTableOrder); 294 | PerformUpdate(pDs, pTableOrder); 295 | m_CurrentUpdating = ""; 296 | } 297 | 298 | private void PerformInsert(DataSet pDs, List pTableOrder) 299 | { 300 | foreach (string MyTableName in pTableOrder) 301 | { 302 | DataRow[] MyRows = pDs.Tables[MyTableName].Select("", "", DataViewRowState.Added); 303 | if (MyRows.Length > 0) 304 | { 305 | m_CurrentUpdating = MyTableName; 306 | DbDataAdapter MyDa = CreateDataAdapter(pDs, MyTableName); 307 | PrepareInsert(MyDa, pDs.Tables[MyTableName]); 308 | MyDa.UpdateBatchSize = m_BatchSize; 309 | if (m_BatchSize > 1) 310 | MyDa.InsertCommand.UpdatedRowSource = UpdateRowSource.None; 311 | MyDa.Update(MyRows); 312 | } 313 | } 314 | } 315 | 316 | private void PerformUpdate(DataSet pDs, List pTableOrder) 317 | { 318 | foreach (string MyTableName in pTableOrder) 319 | { 320 | DataRow[] MyRows = pDs.Tables[MyTableName].Select("", "", DataViewRowState.ModifiedCurrent); 321 | if (MyRows.Length > 0) 322 | { 323 | m_CurrentUpdating = MyTableName; 324 | DbDataAdapter MyDa = CreateDataAdapter(pDs, MyTableName); 325 | DbCommandBuilder MyCB = CreateCommandBuilder(MyDa); 326 | MyDa.UpdateCommand = MyCB.GetUpdateCommand(); 327 | MyDa.UpdateCommand.Transaction = m_Trans; 328 | MyDa.UpdateBatchSize = m_BatchSize; 329 | MyDa.Update(MyRows); 330 | } 331 | } 332 | } 333 | 334 | private void PerformDelete(DataSet pDs, List pTableOrder) 335 | { 336 | foreach (string MyTableName in pTableOrder) 337 | { 338 | DataRow[] MyRows = pDs.Tables[MyTableName].Select("", "", DataViewRowState.Deleted); 339 | if (MyRows.Length > 0) 340 | { 341 | m_CurrentUpdating = MyTableName; 342 | DbDataAdapter MyDa = CreateDataAdapter(pDs, MyTableName); 343 | DbCommandBuilder MyCB = CreateCommandBuilder(MyDa); 344 | MyDa.DeleteCommand = MyCB.GetDeleteCommand(); 345 | MyDa.DeleteCommand.Transaction = m_Trans; 346 | MyDa.UpdateBatchSize = m_BatchSize; 347 | MyDa.Update(MyRows); 348 | } 349 | } 350 | } 351 | 352 | protected virtual void PrepareInsert(DbDataAdapter pDA, DataTable pDt) 353 | { 354 | DbCommandBuilder MyCB = CreateCommandBuilder(pDA); 355 | DbCommand MyCmdSrc = MyCB.GetInsertCommand(); 356 | DbCommand MyCmdDest = CreateCommand(MyCmdSrc.CommandText); 357 | 358 | if (m_PrimaryKeyRequest && (pDt.PrimaryKey == null || pDt.PrimaryKey.Length == 0)) 359 | throw new Exception("PrimaryKey isn't exist!"); 360 | 361 | if (m_PrimaryKeyRequest && pDt.PrimaryKey[0].AutoIncrement) 362 | MyCmdDest.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord; 363 | else 364 | MyCmdDest.UpdatedRowSource = UpdateRowSource.None; 365 | 366 | int MyParamCount = MyCmdSrc.Parameters.Count; 367 | DbParameter[] MyP = new DbParameter[MyParamCount]; 368 | 369 | MyCmdSrc.Parameters.CopyTo(MyP, 0); 370 | while (MyCmdSrc.Parameters.Count > 0) 371 | MyCmdSrc.Parameters.Remove(MyCmdSrc.Parameters[MyCmdSrc.Parameters.Count - 1]); 372 | 373 | for (int i = 0; i < MyParamCount; i++) 374 | MyCmdDest.Parameters.Add(MyP[i]); 375 | 376 | pDA.InsertCommand = MyCmdDest; 377 | pDA.InsertCommand.Transaction = m_Trans; 378 | } 379 | 380 | #endregion 381 | 382 | #region *** Transaction managment *** 383 | 384 | public bool TransactionBegin() 385 | { 386 | if (m_Trans == null || m_MultiTransactionMode) 387 | { 388 | if (m_Trans == null) 389 | { 390 | m_Trans = m_Connection.BeginTransaction(); 391 | } 392 | m_TransactionCount++; 393 | return true; 394 | } 395 | else 396 | { 397 | return false; 398 | } 399 | } 400 | 401 | public void TransactionCommit() 402 | { 403 | if (m_Trans != null || m_MultiTransactionMode) 404 | { 405 | if (m_MultiTransactionMode && m_TransactionCount <= 0) 406 | { 407 | throw new Exception("The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION."); 408 | } 409 | m_TransactionCount--; 410 | if (m_TransactionCount == 0) 411 | { 412 | m_Trans.Commit(); 413 | m_Trans = null; 414 | } 415 | } 416 | } 417 | 418 | public void TransactionRollback() 419 | { 420 | if (m_MultiTransactionMode && m_TransactionCount <= 0) 421 | { 422 | throw new Exception("The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION."); 423 | } 424 | try 425 | { 426 | if (m_Trans != null) 427 | { 428 | m_Trans.Rollback(); 429 | } 430 | } 431 | catch (InvalidOperationException) 432 | { 433 | Connect(); 434 | } 435 | m_Trans = null; 436 | m_TransactionCount = 0; 437 | } 438 | 439 | public bool IsTransaction() 440 | { 441 | return (m_Trans != null); 442 | } 443 | 444 | #endregion 445 | 446 | #region *** PUBLIC METHODS *** 447 | 448 | public virtual string Quote(string pSqlText) 449 | { 450 | return pSqlText.Replace("'", "''"); 451 | } 452 | 453 | public virtual string QuotedName(string pName) 454 | { 455 | return pName; 456 | } 457 | 458 | 459 | #endregion 460 | 461 | #region *** PRIVATE Methods *** 462 | 463 | protected void Connect() 464 | { 465 | Connect(GetConnectionString()); 466 | } 467 | 468 | protected void Connect(string pConnectionString) 469 | { 470 | try 471 | { 472 | m_Connection = CreateConnection(pConnectionString); 473 | m_Connection.Open(); 474 | m_Logged = (m_Connection.State == ConnectionState.Open); 475 | LoginException = null; 476 | } 477 | catch (Exception ex) 478 | { 479 | LoginException = ex; 480 | m_Logged = false; 481 | } 482 | } 483 | 484 | #endregion 485 | 486 | #region *** PROPERTIES *** 487 | 488 | public DbConnection Connection 489 | { 490 | get { return m_Connection; } 491 | } 492 | 493 | public string DbName 494 | { 495 | get { return m_DbName; } 496 | } 497 | 498 | public bool IsLogged 499 | { 500 | get { return m_Logged; } 501 | } 502 | 503 | public int DefautTimeOut 504 | { 505 | get { return m_CommandTimeoutDef; } 506 | set { m_CommandTimeoutDef = value; } 507 | } 508 | 509 | public int TimeOut 510 | { 511 | get { return m_CommandTimeout; } 512 | set { m_CommandTimeout = value; } 513 | } 514 | 515 | public bool PrimaryKeyRequest 516 | { 517 | get { return m_PrimaryKeyRequest; } 518 | set { m_PrimaryKeyRequest = value; } 519 | } 520 | 521 | public string ServerVersion 522 | { 523 | get { return m_Connection.ServerVersion; } 524 | } 525 | 526 | public DbTransaction Transaction 527 | { 528 | get { return m_Trans; } 529 | } 530 | 531 | public bool InTransaction 532 | { 533 | get { return IsTransaction(); } 534 | } 535 | 536 | public bool IsMultiTransactionMode 537 | { 538 | get { return m_MultiTransactionMode; } 539 | set 540 | { 541 | if (IsTransaction()) 542 | { 543 | throw new Exception("Disallow set MultiTransaction Mode during transaction open."); 544 | } 545 | else 546 | { 547 | m_MultiTransactionMode = value; 548 | } 549 | } 550 | } 551 | 552 | public int TransactionCount 553 | { 554 | get { return m_TransactionCount; } 555 | } 556 | 557 | #endregion 558 | 559 | } 560 | 561 | } 562 | -------------------------------------------------------------------------------- /CAMOsoft/CAMOsoft.DbUtils/MsSqlCmd.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Player/DataScriptWriter/d24e86a6a413f796f3247f82d84a3b144e81c225/CAMOsoft/CAMOsoft.DbUtils/MsSqlCmd.cs -------------------------------------------------------------------------------- /CAMOsoft/CAMOsoft.DbUtils/MsSqlSession.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Data.Common; 4 | using System.Data.SqlClient; 5 | 6 | namespace CAMOsoft.DbUtils 7 | { 8 | 9 | public class MsSqlSession : DbSession 10 | { 11 | 12 | #region *** members *** 13 | 14 | private int m_SPID = 0; 15 | //private MsSqlCmd m_CurrentSP = null; 16 | 17 | #endregion 18 | 19 | #region *** SYSTEM *** 20 | 21 | public MsSqlSession(string pConnectionString) : base(pConnectionString) { } 22 | 23 | public MsSqlSession(bool UsePoolingConnection) : base(UsePoolingConnection) { } 24 | 25 | public void LoginWindowsAuth(string pDbServer, string pDbName) 26 | { 27 | base.Login(pDbServer, null, null, pDbName); 28 | } 29 | public void LoginWindowsAuth(string pDbServer) 30 | { 31 | base.Login(pDbServer, null, null, null); 32 | } 33 | 34 | public void LoginSQLAuth(string pDbServer, string pDbUserName, string pDbUserPass, string pDbName) 35 | { 36 | base.Login(pDbServer, pDbUserName, pDbUserPass, pDbName); 37 | } 38 | public void LoginSQLAuth(string pDbServer, string pDbUserName, string pDbUserPass) 39 | { 40 | base.Login(pDbServer, pDbUserName, pDbUserPass, null); 41 | } 42 | 43 | public void ChangeDatabase(string dbName) 44 | { 45 | base.Execute("USE " + QuotedName(dbName)); 46 | } 47 | 48 | protected override void PostInit() 49 | { 50 | //m_CurrentSP = new MsSqlCmd(this); 51 | } 52 | 53 | #endregion 54 | 55 | #region *** ABSTRACT *** 56 | 57 | public override DbDataAdapter CreateDataAdapter() 58 | { 59 | return new SqlDataAdapter(); 60 | } 61 | public override DbCommand CreateCommand() 62 | { 63 | return new SqlCommand(); 64 | } 65 | public override DbCommandBuilder CreateCommandBuilder(DbDataAdapter pDa) 66 | { 67 | return new SqlCommandBuilder(pDa as SqlDataAdapter); 68 | } 69 | public override string GetConnectionString() 70 | { 71 | SqlConnectionStringBuilder MyBuilder = new SqlConnectionStringBuilder(); 72 | MyBuilder.DataSource = m_DbServer; 73 | MyBuilder.InitialCatalog = m_DbName == null ? "" : m_DbName; 74 | if (m_DbUserName == null && m_DbUserPass == null) 75 | MyBuilder.IntegratedSecurity = true; 76 | else 77 | { 78 | MyBuilder.UserID = m_DbUserName; 79 | MyBuilder.Password = m_DbUserPass; 80 | } 81 | MyBuilder.Pooling = m_Pooling; 82 | if (m_Pooling) 83 | MyBuilder.MaxPoolSize = m_MaxPoolingSize; 84 | else 85 | MyBuilder.MaxPoolSize = 1; 86 | return MyBuilder.ConnectionString; 87 | } 88 | public override DbConnection CreateConnection(string pConnectionString) 89 | { 90 | return new SqlConnection(pConnectionString); 91 | } 92 | 93 | #endregion 94 | 95 | #region *** UPDATE / SAVE *** 96 | 97 | protected override void PrepareInsert(DbDataAdapter pDA, DataTable pDt) 98 | { 99 | DbCommandBuilder MyCB = CreateCommandBuilder(pDA); 100 | DbCommand MyCmdSrc = MyCB.GetInsertCommand(); 101 | DbCommand MyCmdDest = CreateCommand(MyCmdSrc.CommandText); 102 | 103 | if (m_PrimaryKeyRequest && (pDt.PrimaryKey == null || pDt.PrimaryKey.Length == 0)) 104 | throw new Exception("PrimaryKey isn't exist!"); 105 | 106 | if (m_PrimaryKeyRequest && pDt.PrimaryKey[0].AutoIncrement) 107 | { 108 | MyCmdDest.CommandText = MyCmdDest.CommandText + "; SELECT SCOPE_IDENTITY() AS " + pDt.PrimaryKey[0].ColumnName; 109 | MyCmdDest.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord; 110 | } 111 | else 112 | MyCmdDest.UpdatedRowSource = UpdateRowSource.None; 113 | 114 | int MyParamCount = MyCmdSrc.Parameters.Count; 115 | DbParameter[] MyP = new DbParameter[MyParamCount]; 116 | 117 | MyCmdSrc.Parameters.CopyTo(MyP, 0); 118 | while (MyCmdSrc.Parameters.Count > 0) 119 | MyCmdSrc.Parameters.Remove(MyCmdSrc.Parameters[MyCmdSrc.Parameters.Count - 1]); 120 | 121 | for (int i = 0; i < MyParamCount; i++) 122 | MyCmdDest.Parameters.Add(MyP[i]); 123 | 124 | pDA.InsertCommand = MyCmdDest; 125 | pDA.InsertCommand.Transaction = base.Transaction; 126 | } 127 | 128 | public void BulkInsert(DataTable pTable, string pDstTableName) 129 | { 130 | System.Data.SqlClient.SqlBulkCopy mySqlBulk = new SqlBulkCopy(this.Connection as SqlConnection, SqlBulkCopyOptions.Default, this.Transaction as SqlTransaction); 131 | mySqlBulk.DestinationTableName = "tmpBulkInsert"; 132 | mySqlBulk.WriteToServer(pTable); 133 | } 134 | 135 | #endregion 136 | 137 | #region *** PUBLIC METHODS *** 138 | 139 | public new string Quote(string pSqlText) 140 | { 141 | return pSqlText.Replace("'", "''"); 142 | } 143 | 144 | public override string QuotedName(string pName) 145 | { 146 | return pName.StartsWith("[") ? pName : "[" + pName + "]"; 147 | } 148 | 149 | #endregion 150 | 151 | #region *** PUBLIC SELECT *** 152 | 153 | 154 | public int SelectValueIntParam(string pSql, params object[] pParamValues) 155 | { 156 | return int.Parse(SelectValueParam(pSql, pParamValues).ToString()); 157 | } 158 | 159 | public object SelectValueParam(string pSql, params object[] pParamValues) 160 | { 161 | if (pParamValues.Length == 0) return base.SelectValue(pSql); 162 | 163 | MsSqlCmd myCmd = new MsSqlCmd(this); 164 | myCmd.SetSql(pSql); 165 | myCmd.AddParamsIn(pParamValues); 166 | return myCmd.ExecuteScalar(); 167 | } 168 | 169 | 170 | #endregion 171 | 172 | #region *** PROPERTIES *** 173 | 174 | public int SPID 175 | { 176 | get 177 | { 178 | if (m_SPID == 0 && base.IsLogged) 179 | { 180 | m_SPID = SelectValueInt("SELECT @@SPID"); 181 | } 182 | return m_SPID; 183 | } 184 | } 185 | 186 | #endregion 187 | 188 | } 189 | 190 | } 191 | -------------------------------------------------------------------------------- /CAMOsoft/CAMOsoft.DbUtils/SqlServerTypes/Loader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace SqlServerTypes 6 | { 7 | /// 8 | /// Utility methods related to CLR Types for SQL Server 9 | /// 10 | public class Utilities 11 | { 12 | [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] 13 | private static extern IntPtr LoadLibrary(string libname); 14 | 15 | /// 16 | /// Loads the required native assemblies for the current architecture (x86 or x64) 17 | /// 18 | /// 19 | /// Root path of the current application. Use Server.MapPath(".") for ASP.NET applications 20 | /// and AppDomain.CurrentDomain.BaseDirectory for desktop applications. 21 | /// 22 | public static void LoadNativeAssemblies(string rootApplicationPath) 23 | { 24 | //var nativeBinaryPath = IntPtr.Size > 4 25 | // ? Path.Combine(rootApplicationPath, @"RequiredDLL\x64\") 26 | // : Path.Combine(rootApplicationPath, @"RequiredDLL\x86\"); 27 | 28 | //LoadNativeAssembly(nativeBinaryPath, "msvcr120.dll"); 29 | //LoadNativeAssembly(nativeBinaryPath, "SqlServerSpatial140.dll"); 30 | } 31 | 32 | private static void LoadNativeAssembly(string nativeBinaryPath, string assemblyName) 33 | { 34 | var path = Path.Combine(nativeBinaryPath, assemblyName); 35 | var ptr = LoadLibrary(path); 36 | if (ptr == IntPtr.Zero) 37 | { 38 | throw new Exception(string.Format( 39 | "Error loading {0} (ErrorCode: {1})", 40 | assemblyName, 41 | Marshal.GetLastWin32Error())); 42 | } 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /CAMOsoft/CAMOsoft.DbUtils/SqlServerTypes/readme.htm: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Microsoft.SqlServer.Types 5 | 17 | 18 | 19 |
20 |

Action required to load native assemblies

21 |

22 | To deploy an application that uses spatial data types to a machine that does not have 'System CLR Types for SQL Server' installed you also need to deploy the native assembly SqlServerSpatial140.dll. Both x86 (32 bit) and x64 (64 bit) versions of this assembly have been added to your project under the SqlServerTypes\x86 and SqlServerTypes\x64 subdirectories. The native assembly msvcr120.dll is also included in case the C++ runtime is not installed. 23 |

24 |

25 | You need to add code to load the correct one of these assemblies at runtime (depending on the current architecture). 26 |

27 |

ASP.NET Web Sites

28 |

29 | For ASP.NET Web Sites, add the following block of code to the code behind file of the Web Form where you have added Report Viewer Control: 30 |

31 |     Default.aspx.cs:
32 |         
33 |     public partial class _Default : System.Web.UI.Page
34 |     {
35 |         static bool _isSqlTypesLoaded = false;
36 | 
37 |         public _Default()
38 |         {
39 |             if (!_isSqlTypesLoaded)
40 |             {
41 |                 SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~"));
42 |                 _isSqlTypesLoaded = true;
43 |             }
44 |             
45 |         }
46 |     }
47 | 
48 |

49 |

ASP.NET Web Applications

50 |

51 | For ASP.NET Web Applications, add the following line of code to the Application_Start method in Global.asax.cs: 52 |

    SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
53 |

54 |

Desktop Applications

55 |

56 | For desktop applications, add the following line of code to run before any spatial operations are performed: 57 |

    SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
58 |

59 |
60 | 61 | -------------------------------------------------------------------------------- /CAMOsoft/CAMOsoft.DbUtils/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /ChangesLog.txt: -------------------------------------------------------------------------------- 1 | SQLPlayer Data Script Writer - Changes Log 2 | ========================================== 3 | 4 | ver.2.4 @ 08/09/2021 5 | - Support for datetimeoffset type (#20) 6 | - Config data types to not be scripted (#20) 7 | - Fixed SQL reading structure of a table (#23) 8 | - Do not script calculated columns (#18) 9 | - Option to open target folder in Explorer 10 | 11 | ver.2.3 @ 02/12/2020 12 | - Support for Temporal tables (#10) 13 | - Support for Time data type (#14) 14 | - Fixed: Showing the wrong number of rows in a table (#12) 15 | 16 | ver.2.2 @ 12/06/2020 17 | - Support for Binary and Varbinary 18 | 19 | ver.2.1 @ 17/04/2020 20 | - Added URL to project on GitHub 21 | - Data type NTEXT is supported now 22 | - Unicode types (SYSNAME, NTEXT, NCHAR, NVARCHAR) values are correctly formatted with 'N' prefix 23 | 24 | ver.2.0 @ 02/04/2018 25 | The application has been built. 26 | -------------------------------------------------------------------------------- /ConnectDbForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Text; 7 | using System.Windows.Forms; 8 | using DevExpress.XtraEditors; 9 | using System.Security.Cryptography; 10 | //using CAMOsoft.Common; 11 | using System.Xml; 12 | 13 | public partial class ConnectDbForm : DevExpress.XtraEditors.XtraForm 14 | { 15 | 16 | private CAMOsoft.DbUtils.MsSqlSession _db = null; 17 | private bool _dblistLoaded = false; 18 | 19 | public ConnectDbForm(string AppName, string AreaName) 20 | { 21 | InitializeComponent(); 22 | lblAreaName.Text = AppName + " " + AreaName; 23 | } 24 | 25 | 26 | 27 | private void ReloadDatabaseList() 28 | { 29 | if (_dblistLoaded) return; 30 | if (ConnectToDb("master")) 31 | { 32 | DataTable dblist = _db.SelectTable("SELECT [name] FROM sys.databases ORDER BY [name]", "databaseList"); 33 | cmbDbName.Properties.Items.Clear(); 34 | foreach (DataRow dr in dblist.Rows) 35 | { 36 | cmbDbName.Properties.Items.Add(dr[0].ToString()); 37 | } 38 | _dblistLoaded = true; 39 | } 40 | } 41 | 42 | private void btnOK_Click(object sender, EventArgs e) 43 | { 44 | this.Cursor = Cursors.WaitCursor; 45 | this.Enabled = false; 46 | ConnectToDb(cmbDbName.Text); 47 | this.Enabled = true; 48 | this.Cursor = Cursors.Default; 49 | if (_db.IsLogged) 50 | { 51 | DialogResult = DialogResult.OK; 52 | } 53 | else 54 | { 55 | MessageBox.Show(_db.LoginException.Message, "Connect to Server", MessageBoxButtons.OK, MessageBoxIcon.Warning); 56 | } 57 | } 58 | 59 | private bool ConnectToDb(string dbname) 60 | { 61 | if (cbeAuth.SelectedIndex == 0) 62 | { 63 | _db = new CAMOsoft.DbUtils.MsSqlSession(true); 64 | _db.LoginWindowsAuth(txtServer.Text, cmbDbName.Text); 65 | } 66 | else 67 | { 68 | _db = new CAMOsoft.DbUtils.MsSqlSession(true); 69 | _db.LoginSQLAuth(txtServer.Text, txtUser.Text, txtPass.Text, cmbDbName.Text); 70 | } 71 | return _db.IsLogged; 72 | } 73 | 74 | private void cbeAuth_SelectedIndexChanged(object sender, EventArgs e) 75 | { 76 | bool WinAuth = cbeAuth.SelectedIndex == 0; 77 | txtUser.Enabled = !WinAuth; 78 | txtPass.Enabled = !WinAuth; 79 | lblUser.Enabled = !WinAuth; 80 | lblPass.Enabled = !WinAuth; 81 | } 82 | 83 | private void ConnectDbForm_Load(object sender, EventArgs e) 84 | { 85 | cbeAuth.SelectedIndex = 0; 86 | } 87 | 88 | public string AreaName 89 | { 90 | get { return lblAreaName.Text; } 91 | } 92 | 93 | public CAMOsoft.DbUtils.MsSqlSession Db 94 | { 95 | get 96 | { 97 | return _db; 98 | } 99 | 100 | } 101 | 102 | private void txtServer_EditValueChanged(object sender, EventArgs e) 103 | { 104 | _dblistLoaded = false; 105 | } 106 | 107 | private void cmbDbName_Enter(object sender, EventArgs e) 108 | { 109 | ReloadDatabaseList(); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /ConnectDbForm.designer.cs: -------------------------------------------------------------------------------- 1 | //namespace SimpleCRM 2 | //{ 3 | partial class ConnectDbForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ConnectDbForm)); 32 | this.labelControl1 = new DevExpress.XtraEditors.LabelControl(); 33 | this.txtUser = new DevExpress.XtraEditors.TextEdit(); 34 | this.lblUser = new DevExpress.XtraEditors.LabelControl(); 35 | this.txtPass = new DevExpress.XtraEditors.TextEdit(); 36 | this.lblPass = new DevExpress.XtraEditors.LabelControl(); 37 | this.labelControl4 = new DevExpress.XtraEditors.LabelControl(); 38 | this.btnOK = new DevExpress.XtraEditors.SimpleButton(); 39 | this.btnCancel = new DevExpress.XtraEditors.SimpleButton(); 40 | this.labelControl5 = new DevExpress.XtraEditors.LabelControl(); 41 | this.cbeAuth = new DevExpress.XtraEditors.ComboBoxEdit(); 42 | this.labelControl6 = new DevExpress.XtraEditors.LabelControl(); 43 | this.pictureBox1 = new System.Windows.Forms.PictureBox(); 44 | this.lblAreaName = new System.Windows.Forms.Label(); 45 | this.cmbDbName = new DevExpress.XtraEditors.ComboBoxEdit(); 46 | this.txtServer = new DevExpress.XtraEditors.TextEdit(); 47 | ((System.ComponentModel.ISupportInitialize)(this.txtUser.Properties)).BeginInit(); 48 | ((System.ComponentModel.ISupportInitialize)(this.txtPass.Properties)).BeginInit(); 49 | ((System.ComponentModel.ISupportInitialize)(this.cbeAuth.Properties)).BeginInit(); 50 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); 51 | ((System.ComponentModel.ISupportInitialize)(this.cmbDbName.Properties)).BeginInit(); 52 | ((System.ComponentModel.ISupportInitialize)(this.txtServer.Properties)).BeginInit(); 53 | this.SuspendLayout(); 54 | // 55 | // labelControl1 56 | // 57 | this.labelControl1.Location = new System.Drawing.Point(12, 100); 58 | this.labelControl1.Name = "labelControl1"; 59 | this.labelControl1.Size = new System.Drawing.Size(65, 13); 60 | this.labelControl1.TabIndex = 0; 61 | this.labelControl1.Text = "&Server name:"; 62 | // 63 | // txtUser 64 | // 65 | this.txtUser.Location = new System.Drawing.Point(179, 161); 66 | this.txtUser.Name = "txtUser"; 67 | this.txtUser.Properties.MaxLength = 128; 68 | this.txtUser.Size = new System.Drawing.Size(218, 20); 69 | this.txtUser.TabIndex = 5; 70 | // 71 | // lblUser 72 | // 73 | this.lblUser.Location = new System.Drawing.Point(25, 164); 74 | this.lblUser.Name = "lblUser"; 75 | this.lblUser.Size = new System.Drawing.Size(55, 13); 76 | this.lblUser.TabIndex = 6; 77 | this.lblUser.Text = "&User name:"; 78 | // 79 | // txtPass 80 | // 81 | this.txtPass.Location = new System.Drawing.Point(179, 187); 82 | this.txtPass.Name = "txtPass"; 83 | this.txtPass.Properties.MaxLength = 128; 84 | this.txtPass.Properties.PasswordChar = '*'; 85 | this.txtPass.Size = new System.Drawing.Size(218, 20); 86 | this.txtPass.TabIndex = 7; 87 | // 88 | // lblPass 89 | // 90 | this.lblPass.Location = new System.Drawing.Point(25, 190); 91 | this.lblPass.Name = "lblPass"; 92 | this.lblPass.Size = new System.Drawing.Size(50, 13); 93 | this.lblPass.TabIndex = 8; 94 | this.lblPass.Text = "&Password:"; 95 | // 96 | // labelControl4 97 | // 98 | this.labelControl4.Location = new System.Drawing.Point(12, 126); 99 | this.labelControl4.Name = "labelControl4"; 100 | this.labelControl4.Size = new System.Drawing.Size(74, 13); 101 | this.labelControl4.TabIndex = 2; 102 | this.labelControl4.Text = "&Authentication:"; 103 | // 104 | // btnOK 105 | // 106 | this.btnOK.Location = new System.Drawing.Point(209, 302); 107 | this.btnOK.Name = "btnOK"; 108 | this.btnOK.Size = new System.Drawing.Size(85, 28); 109 | this.btnOK.TabIndex = 11; 110 | this.btnOK.Text = "&Connect"; 111 | this.btnOK.Click += new System.EventHandler(this.btnOK_Click); 112 | // 113 | // btnCancel 114 | // 115 | this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; 116 | this.btnCancel.Location = new System.Drawing.Point(312, 302); 117 | this.btnCancel.Name = "btnCancel"; 118 | this.btnCancel.Size = new System.Drawing.Size(85, 28); 119 | this.btnCancel.TabIndex = 12; 120 | this.btnCancel.Text = "Cancel"; 121 | // 122 | // labelControl5 123 | // 124 | this.labelControl5.AutoSizeMode = DevExpress.XtraEditors.LabelAutoSizeMode.None; 125 | this.labelControl5.LineOrientation = DevExpress.XtraEditors.LabelLineOrientation.Horizontal; 126 | this.labelControl5.LineVisible = true; 127 | this.labelControl5.Location = new System.Drawing.Point(-2, 275); 128 | this.labelControl5.Name = "labelControl5"; 129 | this.labelControl5.Size = new System.Drawing.Size(419, 26); 130 | this.labelControl5.TabIndex = 11; 131 | // 132 | // cbeAuth 133 | // 134 | this.cbeAuth.Location = new System.Drawing.Point(159, 123); 135 | this.cbeAuth.Name = "cbeAuth"; 136 | this.cbeAuth.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { 137 | new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)}); 138 | this.cbeAuth.Properties.DropDownRows = 2; 139 | this.cbeAuth.Properties.Items.AddRange(new object[] { 140 | "Windows Authentication", 141 | "SQL Server Authentication"}); 142 | this.cbeAuth.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; 143 | this.cbeAuth.Size = new System.Drawing.Size(238, 20); 144 | this.cbeAuth.TabIndex = 3; 145 | this.cbeAuth.SelectedIndexChanged += new System.EventHandler(this.cbeAuth_SelectedIndexChanged); 146 | // 147 | // labelControl6 148 | // 149 | this.labelControl6.Location = new System.Drawing.Point(12, 216); 150 | this.labelControl6.Name = "labelControl6"; 151 | this.labelControl6.Size = new System.Drawing.Size(50, 13); 152 | this.labelControl6.TabIndex = 4; 153 | this.labelControl6.Text = "&Database:"; 154 | // 155 | // pictureBox1 156 | // 157 | this.pictureBox1.Location = new System.Drawing.Point(0, 0); 158 | this.pictureBox1.Name = "pictureBox1"; 159 | this.pictureBox1.Size = new System.Drawing.Size(447, 77); 160 | this.pictureBox1.TabIndex = 15; 161 | this.pictureBox1.TabStop = false; 162 | // 163 | // lblAreaName 164 | // 165 | this.lblAreaName.AutoSize = true; 166 | this.lblAreaName.BackColor = System.Drawing.Color.Transparent; 167 | this.lblAreaName.Font = new System.Drawing.Font("Calibri", 14F, System.Drawing.FontStyle.Bold); 168 | this.lblAreaName.Location = new System.Drawing.Point(61, 26); 169 | this.lblAreaName.Name = "lblAreaName"; 170 | this.lblAreaName.Size = new System.Drawing.Size(111, 23); 171 | this.lblAreaName.TabIndex = 16; 172 | this.lblAreaName.Text = "[Area Name]"; 173 | // 174 | // cmbDbName 175 | // 176 | this.cmbDbName.Location = new System.Drawing.Point(159, 213); 177 | this.cmbDbName.Name = "cmbDbName"; 178 | this.cmbDbName.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { 179 | new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)}); 180 | this.cmbDbName.Properties.DropDownRows = 10; 181 | this.cmbDbName.Size = new System.Drawing.Size(238, 20); 182 | this.cmbDbName.TabIndex = 17; 183 | this.cmbDbName.Enter += new System.EventHandler(this.cmbDbName_Enter); 184 | // 185 | // txtServer 186 | // 187 | this.txtServer.Location = new System.Drawing.Point(159, 97); 188 | this.txtServer.Name = "txtServer"; 189 | this.txtServer.Size = new System.Drawing.Size(238, 20); 190 | this.txtServer.TabIndex = 0; 191 | this.txtServer.EditValueChanged += new System.EventHandler(this.txtServer_EditValueChanged); 192 | // 193 | // ConnectDbForm 194 | // 195 | this.AcceptButton = this.btnOK; 196 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 197 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 198 | this.CancelButton = this.btnCancel; 199 | this.ClientSize = new System.Drawing.Size(409, 342); 200 | this.Controls.Add(this.txtServer); 201 | this.Controls.Add(this.cmbDbName); 202 | this.Controls.Add(this.lblAreaName); 203 | this.Controls.Add(this.pictureBox1); 204 | this.Controls.Add(this.labelControl6); 205 | this.Controls.Add(this.cbeAuth); 206 | this.Controls.Add(this.labelControl5); 207 | this.Controls.Add(this.btnCancel); 208 | this.Controls.Add(this.btnOK); 209 | this.Controls.Add(this.labelControl4); 210 | this.Controls.Add(this.txtPass); 211 | this.Controls.Add(this.lblPass); 212 | this.Controls.Add(this.txtUser); 213 | this.Controls.Add(this.lblUser); 214 | this.Controls.Add(this.labelControl1); 215 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 216 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); 217 | this.MaximizeBox = false; 218 | this.MinimizeBox = false; 219 | this.Name = "ConnectDbForm"; 220 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 221 | this.Text = "Connect to Server"; 222 | this.Load += new System.EventHandler(this.ConnectDbForm_Load); 223 | ((System.ComponentModel.ISupportInitialize)(this.txtUser.Properties)).EndInit(); 224 | ((System.ComponentModel.ISupportInitialize)(this.txtPass.Properties)).EndInit(); 225 | ((System.ComponentModel.ISupportInitialize)(this.cbeAuth.Properties)).EndInit(); 226 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); 227 | ((System.ComponentModel.ISupportInitialize)(this.cmbDbName.Properties)).EndInit(); 228 | ((System.ComponentModel.ISupportInitialize)(this.txtServer.Properties)).EndInit(); 229 | this.ResumeLayout(false); 230 | this.PerformLayout(); 231 | 232 | } 233 | 234 | #endregion 235 | 236 | private DevExpress.XtraEditors.LabelControl labelControl1; 237 | private DevExpress.XtraEditors.TextEdit txtUser; 238 | private DevExpress.XtraEditors.LabelControl lblUser; 239 | private DevExpress.XtraEditors.TextEdit txtPass; 240 | private DevExpress.XtraEditors.LabelControl lblPass; 241 | private DevExpress.XtraEditors.LabelControl labelControl4; 242 | private DevExpress.XtraEditors.SimpleButton btnOK; 243 | private DevExpress.XtraEditors.SimpleButton btnCancel; 244 | private DevExpress.XtraEditors.LabelControl labelControl5; 245 | private DevExpress.XtraEditors.ComboBoxEdit cbeAuth; 246 | private DevExpress.XtraEditors.LabelControl labelControl6; 247 | private System.Windows.Forms.PictureBox pictureBox1; 248 | private System.Windows.Forms.Label lblAreaName; 249 | private DevExpress.XtraEditors.ComboBoxEdit cmbDbName; 250 | private DevExpress.XtraEditors.TextEdit txtServer; 251 | } 252 | //} -------------------------------------------------------------------------------- /ConnectDbForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | 123 | AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAABAAABILAAASCwAAAAAAAAAA 124 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAANAAAADwAA 125 | AAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 126 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADQAA 127 | ACsAAAA0AAAAIgAAABYAAAARAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 128 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAUAAAALAAAAEQAAABQAAAAWAAAAFgAA 129 | ABYAAAAlq6inxoaEgf8AAABIAAAAQwAAADcAAAAiAAAAFgAAABYAAAAWAAAAFgAAABYAAAAWAAAAEQAA 130 | AAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAsAAAAWAAAAIAAAAC0AAAA3AAAAPgAA 131 | AEEAAABDAAAAQwAAAEiPjIv/19XU/4eGgv+Eg3//f319/wAAAEgAAABDAAAAQwAAAEMAAABDAAAAQwAA 132 | AEMAAAA3AAAAHAAAAAYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAATAAAAKwAAAD5HRUBtc3Bop4uH 133 | fd+OiYDqlI+F/5OOhP+SjoP/ko2D/5OOg/+PjIr/ioeF/7e2tP+mpab/d3yE/7uEQP+3g0T/toNF/7aD 134 | Rf+2g0X/toNF/7iERf8AAAA9AAAAIgAAABEAAAAGAAAAAAAAAAAAAAAAAAAADQAAAC54c2uol5GH/6Gb 135 | kf+xqqH/xby0/8vDuv/j2ND/5dzU/+rf1//u49z/9+rj/46Ni//W1NT/wcLE/7C1u/+5fzn/77Nd/+yy 136 | X//ssl//7LJf/+yyX//ssl//7rRg/7aCRP8AAABIAAAANwAAABwAAAAGAAAAAAAAAAAAAAAViIR7waCb 137 | kf/Iwbf/0srB/9PLwv/XzsX/2dDI/93Ty//f1s7/49nR/+fd1v/w5N3/jIyK/+Pk5v/Q1N3/tXo0/++1 138 | Yv/rs2P/6rJj/+qyY//qsmP/6rJj/+qyY//stGX/8bho/7WCRP+4hEX/AAAANwAAABEAAAAAAAAAAAAA 139 | ABaZlIn/yMG3/8vEuv/Oxr3/0Mi//9TLwv/Xzsb/29HJ/97Vzf/i2ND/5dvU/+zh2v/z6OP/jJGW/7R6 140 | M//yt2b/7rZo/+y0aP/stGj/7LRo/+y0aP/stGj/7rZo//G7cv+wfUD/7LFd/+6xW/+4hUb/AAAAEQAA 141 | AAAAAAAAAAAAFpmTif/Kwrn/ysO5/83FvP/QyL//1MvC/9fOxv/b0cn/3tXN/+LY0P/l29T/6uDZ/+/n 142 | 5f+zeDD/9rxu//C5b//ut27/7rdu/+63bv/ut27/7rdu//C4bv/1w4D/rns+//K5bv/ss2D/0JZF5LmF 143 | Rf8AAAAGAAAAAAAAAAAAAAAWmpSK/8nBuP/Jwrj/zMS7/87Gvf/SycD/1czE/9nPx//c08v/4dbO/+TZ 144 | 0v/p3tn/7ufm/7F4Mv/2wnv/8bxz//C7c//wu3P/8Ltz//C7c//yvHP/98uO/616O//0vXL/77Zn/8+Z 145 | TeG7hEH/AAAAIgAAAAYAAAAAAAAAAAAAABaalYn/yMC3/8fAtv/UzcT/5N3W//Lt5f/28er///z1///7 146 | 9P//+/T//vrz//779f//////sHcx//rIiP/0vnn/8755//O+ef/zvnn/9b95//vRnP+teTn/98B4//O6 147 | bf/Snlffu4E6/211gP8AAAA9AAAAHAAAAAYAAAAAAAAAFJqViv/TzMP/9vHq/+/p4//a1c3/ysK6/7yz 148 | q/+0q6H/tKqh/7asov+4rqb/u7Go/762tP+xeDL//M+W//bBff/1wX7/9cF9//fCff/92Kn/rHc3//nD 149 | fv/0vXL/3K90/7l/N/+rsLb/np2e/3V2eP8AAAA9AAAAHAAAAAYAAAAQm5WL//Ls5P+4r6b/pZyR/6ui 150 | mP+7sqn/xbqx/9HIv//Vy8L/5dvT/+je1//t493/8Oro/7B3MP/+1qL/+MSB//fEgv/5xYL//9+1/6x2 151 | Nf/7yIX/98B5/+/Ejf+6fzf/f4aP/8PDxP+vrqz/oJ2b/3Z2dv8AAAA3AAAAEQAAABCNh321tayk/7Wt 152 | ov/Jwbj/08vC/9bNxP/Z0Mj/3dPL/9/Wzv/j2dH/5tzV/+vg2v/v5+b/sHYu///crv/8yIf//MmI///l 153 | wP+rdTP//suL//vFgP/rw5D/t3w1/4iIg60AAAAVhYWG/8TCwP+wrqv/op6c/3h4eP8AAAARAAAAFIuG 154 | fLi3r6T/y8W6/87Gvf/RycD/1MvC/9fOxv/b0cn/3tXN/+LY0P/l29T/6t/Z/+3l4/+vcyn//+O6///N 155 | j///6cv/qnQx///PkP/9yIb/8syd/7h8NP++u7n/i4d/tgAAABQAAAAGhYaG/8bDwf+0srD/d3d4/wAA 156 | AAYAAAAWoJmP/8rCuf/Kw7n/zcW8/9DIv//Uy8L/187G/9vRyf/e1c3/4tjQ/+Xb1P/p3tj/7OLd/+nj 157 | 4/+tcin//+zI/6t0Mf//0pb//8yM//bUqP+4fDP/aG94/9PMxP+jnJL/AAAAFgAAAAAAAAAGiIiI/4qK 158 | iv8AAAAGAAAAAAAAABagmo7/ycG4/8nCuP/MxLv/zsa9/9LJwP/VzMT/2c/H/9zTy//h1s7/5NnS/+nd 159 | 1v/q39j/5t7a/+Xh4P+vdi7//9aZ///Qk//72rP/t3ox/6qus/+cm5z/bnBz/6iglP8AAAAiAAAABgAA 160 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAFqCaj//IwLf/x8C2/9TNxP/k3db/8u3l//bx6v///PX///v0///7 161 | 9P/++vP//frz//368///+/X//////7F1K///7sz//+rH/7R4Lv9ze4P/wcHC/6+tq/+fm5r/c3N1/wAA 162 | ADcAAAARAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUoJqO/9PLw//28er/7+nj/9rVzf/Kwrr/vLOr/7Sr 163 | of+0qqH/tqyj/7iupv+6sKb/u7Co/7mupv+4rqj/uLKv/7N3LP+zdyz/zszJ/+Tf2f94eXv/wsG//6+t 164 | q/+hnpz/d3d4/wAAABEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABCimo//8evk/7evpv+lnJH/q6KY/7uy 165 | qf/FurH/0ci//9XLwv/h18//6N7X/+zh2v/u4tv/6d/Y/+bd1f/Z0cv/0s3H/8/IxP+/t7D/uK6l/7Op 166 | n/94env/xMLA/7Syr/93d3f/AAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEJKMgrW0rKP/ta2i/8nB 167 | uP/Ty8L/1s3E/9nQyP/d08v/39bP/+PZ0f/m3NX/6t/Y/+zg2f/n3db/5NrS/+DX0P/d1Mz/2tHK/9fO 168 | xf/TzML/08vB/8a9s/96e33/f4CB/wAAABIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUkYuAuLau 169 | pP/LxLr/zsa9/9HJwP/Uy8L/187G/9vRyf/e1c3/4tjQ/+Xb1P/p3tf/69/Y/+bc1f/j2dH/39bO/9zS 170 | yv/Yz8f/1czD/9HJwP/Px77/zcW8/7+3rf+SjIC0AAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 171 | ABalnpP/ycG5/8rDuf/Nxbz/0Mi//9TLwv/Xzsb/29HJ/97Vzf/i2ND/5dvU/+ne1//q39j/5tzV/+PZ 172 | 0f/f1s7/3NLK/9jPx//VzMP/0cnA/87Gvf/Lw7r/y8O6/6afk/8AAAAWAAAAAAAAAAAAAAAAAAAAAAAA 173 | AAAAAAAAAAAAFqaflP/IwLj/ycK4/8zDuv/Oxr3/0si//9XLw//Zzsb/3NLK/+DWzv/j2dL/6N3W/+re 174 | 1//l2tP/4dfP/93UzP/az8f/1szE/9PJwP/Px77/zcS7/8rCuf/Kwbn/pp+U/wAAABYAAAAAAAAAAAAA 175 | AAAAAAAAAAAAAAAAAAAAAAAWp6CT/8e+tv/Gv7T/0svC/+Lb0//w6uL/8+7n//368//9+fL//fjy//z4 176 | 8f/8+PH//Pjx//z48f/9+PL//fny//358//z7uf/7+ri/+Lc0//TzMP/x7+2/8i/t/+noJP/AAAAFgAA 177 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABamn5P/z8i///j07P//+vT/+PLr/+ni2v/j2tP/18/G/9TL 178 | wv/Uy8L/1MvC/9TLwv/Uy8L/1MvC/9TLwv/Uy8L/18/G/+Pa0//p4tr/+PLr///69P/08Oj/z8i//6af 179 | k/8AAAAWAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFqaek////PX/6uPb/9PJwP/Nw7n/zsW6/87F 180 | u//Pxrv/z8a8/8/GvP/Pxrz/z8a8/8/GvP/Pxrz/z8a8/8/GvP/Pxrv/zsW7/87Fuv/Nw7n/08nA/+rj 181 | 2////PX/q6SZ/wAAABYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVpp+T/+zl3f/VzML/1czC/9bN 182 | w//XzsP/187E/9fOxP/XzsT/187E/9fOxP/XzsT/187E/9fOxP/XzsT/187E/9fOxP/XzsT/187D/9bN 183 | w//VzML/1czC/+zl3f+mn5P/AAAAFQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA2popb/4NbN/+DW 184 | zP/e1cv/3dTK/93Uyv/d1Mr/3dTK/93Uyv/d1Mr/3dTK/93Uyv/d1Mr/3dTK/93Uyv/d1Mr/3dTK/93U 185 | yv/d1Mr/3dTK/97Vy//f1sz/4NbN/6milv8AAAANAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABKae 186 | k7K1raH/3tXL/+nh1//n39X/5t7U/+Xd0//l3dP/5NzS/+Tc0v/k3NL/5NzS/+Tc0v/k3NL/5NzS/+Tc 187 | 0v/l3dP/5d3T/+be1P/n39X/6eHX/+La0P+1raH/pp6TsgAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 188 | AAAAAAAAAAAAA6eflImqo5b/t66j/8i/tP/Z0cb/3dXK//Hp3//w6N7/8Oje//Do3v/w6N7/8Oje//Do 189 | 3v/w6N7/8Oje//Hp3//d1cr/2dHG/8i/tP+3rqP/qqKW/6eflIkAAAADAAAAAAAAAAAAAAAAAAAAAAAA 190 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGgmY83pp+ThamhltKpoZXiqqKW/6qilv+qopb/qqKW/6qi 191 | lv+qopb/qqKW/6qilv+qopb/qqKW/6mhleKpoZbSpp+ThaCZjzcAAAABAAAAAAAAAAAAAAAAAAAAAAAA 192 | AAAAAAAAAAAAAAAAAAAAAAAA/+H////gP//gAAA/gAAAHwAAAAcAAAADAAAAAwAAAAMAAAADAAAAAwAA 193 | AAEAAAAAAAAAAAAAAAAAAAAAAAAAIQAAAB8AAAAfAAAAHwAAAB8AAAA/AAAAPwAAAD8AAAA/AAAAPwAA 194 | AD8AAAA/AAAAPwAAAD8AAAA/gAAAf+AAAf8= 195 | 196 | 197 | -------------------------------------------------------------------------------- /DataScriptWriter.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {77F673FB-AB5B-46C4-A36A-94FB7D183940} 8 | WinExe 9 | Properties 10 | DataScriptWriter 11 | DataScriptWriter 12 | v4.7.2 13 | 512 14 | SAK 15 | SAK 16 | SAK 17 | SAK 18 | 19 | 20 | 21 | 22 | 23 | AnyCPU 24 | true 25 | full 26 | false 27 | bin\Debug\ 28 | DEBUG;TRACE 29 | prompt 30 | 4 31 | 32 | 33 | AnyCPU 34 | pdbonly 35 | true 36 | bin\Release\ 37 | TRACE 38 | prompt 39 | 4 40 | 41 | 42 | Resources\if_Archive_box_data_file_storage_1886362.ico 43 | 44 | 45 | 46 | packages\XtraEditor.Controls.18.2.4\lib\net45\DevExpress.Data.v18.2.dll 47 | 48 | 49 | packages\XtraEditor.Controls.18.2.4\lib\net45\DevExpress.Office.v18.2.Core.dll 50 | 51 | 52 | packages\XtraEditor.Controls.18.2.4\lib\net45\DevExpress.RichEdit.v18.2.Core.dll 53 | 54 | 55 | packages\XtraEditor.Controls.18.2.4\lib\net45\DevExpress.Utils.v18.2.dll 56 | 57 | 58 | packages\XtraEditor.Controls.18.2.4\lib\net45\DevExpress.Utils.v18.2.UI.dll 59 | 60 | 61 | packages\XtraEditor.Controls.18.2.4\lib\net45\DevExpress.XtraBars.v18.2.dll 62 | 63 | 64 | packages\XtraEditor.Controls.18.2.4\lib\net45\DevExpress.XtraEditors.v18.2.dll 65 | 66 | 67 | packages\XtraEditor.Controls.18.2.4\lib\net45\DevExpress.XtraGrid.v18.2.dll 68 | 69 | 70 | packages\XtraEditor.Controls.18.2.4\lib\net45\DevExpress.XtraLayout.v18.2.dll 71 | 72 | 73 | packages\XtraEditor.Controls.18.2.4\lib\net45\DevExpress.XtraTreeList.v18.2.dll 74 | 75 | 76 | packages\Microsoft.SqlServer.Types.14.0.1016.290\lib\net40\Microsoft.SqlServer.Types.dll 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | Form 93 | 94 | 95 | ConnectDbForm.cs 96 | 97 | 98 | Form 99 | 100 | 101 | frmMain.cs 102 | 103 | 104 | Form 105 | 106 | 107 | frmNoteForm.cs 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | ConnectDbForm.cs 116 | 117 | 118 | frmMain.cs 119 | 120 | 121 | frmNoteForm.cs 122 | 123 | 124 | ResXFileCodeGenerator 125 | Resources.Designer.cs 126 | Designer 127 | 128 | 129 | True 130 | Resources.resx 131 | True 132 | 133 | 134 | Designer 135 | 136 | 137 | SettingsSingleFileGenerator 138 | Settings.Designer.cs 139 | 140 | 141 | True 142 | Settings.settings 143 | True 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | PreserveNewest 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | {3e8ff80a-749b-47ec-941d-1a98eff4540c} 168 | CAMOsoft.DbUtils 169 | 170 | 171 | 172 | 179 | -------------------------------------------------------------------------------- /DataScriptWriter.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29306.81 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataScriptWriter", "DataScriptWriter.csproj", "{77F673FB-AB5B-46C4-A36A-94FB7D183940}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CAMOsoft.DbUtils", "CAMOsoft\CAMOsoft.DbUtils\CAMOsoft.DbUtils.csproj", "{3E8FF80A-749B-47EC-941D-1A98EFF4540C}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x86 = Debug|x86 14 | Release|Any CPU = Release|Any CPU 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {77F673FB-AB5B-46C4-A36A-94FB7D183940}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {77F673FB-AB5B-46C4-A36A-94FB7D183940}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {77F673FB-AB5B-46C4-A36A-94FB7D183940}.Debug|x86.ActiveCfg = Debug|Any CPU 21 | {77F673FB-AB5B-46C4-A36A-94FB7D183940}.Debug|x86.Build.0 = Debug|Any CPU 22 | {77F673FB-AB5B-46C4-A36A-94FB7D183940}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {77F673FB-AB5B-46C4-A36A-94FB7D183940}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {77F673FB-AB5B-46C4-A36A-94FB7D183940}.Release|x86.ActiveCfg = Release|Any CPU 25 | {77F673FB-AB5B-46C4-A36A-94FB7D183940}.Release|x86.Build.0 = Release|Any CPU 26 | {3E8FF80A-749B-47EC-941D-1A98EFF4540C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {3E8FF80A-749B-47EC-941D-1A98EFF4540C}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {3E8FF80A-749B-47EC-941D-1A98EFF4540C}.Debug|x86.ActiveCfg = Debug|x86 29 | {3E8FF80A-749B-47EC-941D-1A98EFF4540C}.Debug|x86.Build.0 = Debug|x86 30 | {3E8FF80A-749B-47EC-941D-1A98EFF4540C}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {3E8FF80A-749B-47EC-941D-1A98EFF4540C}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {3E8FF80A-749B-47EC-941D-1A98EFF4540C}.Release|x86.ActiveCfg = Release|x86 33 | {3E8FF80A-749B-47EC-941D-1A98EFF4540C}.Release|x86.Build.0 = Release|x86 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | GlobalSection(ExtensibilityGlobals) = postSolution 39 | SolutionGuid = {4AE99AB3-76E9-4EF0-ABC8-18C16697772B} 40 | EndGlobalSection 41 | EndGlobal 42 | -------------------------------------------------------------------------------- /Global.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DataScriptWriter 8 | { 9 | public static class Global 10 | { 11 | public static string AppName = ""; 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /OUTPUT/Application.TransactionTypes.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE [dbo].[Populate_Application_TransactionTypes] 2 | AS 3 | BEGIN 4 | /* 5 | Table's data: [Application].[TransactionTypes] 6 | Data Source: [DEV19].[WideWorldImporters] 7 | Created on: 02/12/2020 00:13:12 8 | Scripted by: DEV19\Administrator 9 | Generated by: Data Script Writer - ver. 2.3.0.0 10 | GitHub repo URL: https://github.com/SQLPlayer/DataScriptWriter/ 11 | */ 12 | PRINT 'Populating data into [Application].[TransactionTypes]'; 13 | 14 | IF NOT EXISTS (SELECT TOP (1) * FROM [Application].[TransactionTypes]) 15 | BEGIN 16 | 17 | ;WITH cte_data 18 | as (SELECT [TransactionTypeID], [TransactionTypeName], [LastEditedBy] FROM 19 | (VALUES 20 | (1, N'Customer Invoice', 1) 21 | , (2, N'Customer Credit Note', 1) 22 | , (3, N'Customer Payment Received', 1) 23 | , (4, N'Customer Refund', 1) 24 | , (5, N'Supplier Invoice', 1) 25 | , (6, N'Supplier Credit Note', 1) 26 | , (7, N'Supplier Payment Issued', 1) 27 | , (8, N'Supplier Refund', 1) 28 | , (9, N'Stock Transfer', 1) 29 | , (10, N'Stock Issue', 1) 30 | , (11, N'Stock Receipt', 1) 31 | , (12, N'Stock Adjustment at Stocktake', 1) 32 | , (13, N'Customer Contra', 9) 33 | ) as v ([TransactionTypeID], [TransactionTypeName], [LastEditedBy]) 34 | ) 35 | INSERT INTO [Application].[TransactionTypes] 36 | ([TransactionTypeID], [TransactionTypeName], [LastEditedBy]) 37 | SELECT [TransactionTypeID], [TransactionTypeName], [LastEditedBy] 38 | FROM cte_data; 39 | 40 | END 41 | 42 | -- End data of table: [Application].[TransactionTypes] -- 43 | END 44 | GO 45 | -------------------------------------------------------------------------------- /OUTPUT/Person.AddressType_INSERT.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE [dbo].[Populate_Person_AddressType] 2 | AS 3 | BEGIN 4 | /* 5 | Table's data: [Person].[AddressType] 6 | Data Source: [DEV19].[AdventureWorks2014] 7 | Created on: 18/10/2019 15:00:40 8 | Scripted by: DEV19\Administrator 9 | Generated by Data Script Writer - ver. 2.0.0.0 10 | */ 11 | PRINT 'Populating data into [Person].[AddressType]'; 12 | 13 | IF NOT EXISTS (SELECT TOP (1) * FROM [Person].[AddressType]) 14 | BEGIN 15 | 16 | ;WITH cte_data 17 | as (SELECT [AddressTypeID], [Name], [rowguid], [ModifiedDate] FROM 18 | (VALUES 19 | (1, 'Billing', 'b84f78b1-4efe-4a0e-8cb7-70e9f112f886', '20080430 00:00:00.000') 20 | , (2, 'Home', '41bc2ff6-f0fc-475f-8eb9-cec0805aa0f2', '20080430 00:00:00.000') 21 | , (3, 'Main Office', '8eeec28c-07a2-4fb9-ad0a-42d4a0bbc575', '20080430 00:00:00.000') 22 | , (4, 'Primary', '24cb3088-4345-47c4-86c5-17b535133d1e', '20080430 00:00:00.000') 23 | , (5, 'Shipping', 'b29da3f8-19a3-47da-9daa-15c84f4a83a5', '20080430 00:00:00.000') 24 | , (6, 'Archive', 'a67f238a-5ba2-444b-966c-0467ed9c427f', '20080430 00:00:00.000') 25 | ) as v ([AddressTypeID], [Name], [rowguid], [ModifiedDate]) 26 | ) 27 | INSERT INTO [Person].[AddressType] 28 | ([AddressTypeID], [Name], [rowguid], [ModifiedDate]) 29 | SELECT [AddressTypeID], [Name], [rowguid], [ModifiedDate] 30 | FROM cte_data; 31 | 32 | END 33 | 34 | -- End data of table: [Person].[AddressType] -- 35 | END 36 | GO 37 | -------------------------------------------------------------------------------- /OUTPUT/Person.AddressType_MERGE.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE [dbo].[Populate_Person_AddressType] 2 | AS 3 | BEGIN 4 | /* 5 | Table's data: [Person].[AddressType] 6 | Data Source: [DEV19].[AdventureWorks2014] 7 | Created on: 18/10/2019 14:59:12 8 | Scripted by: DEV19\Administrator 9 | Generated by Data Script Writer - ver. 2.0.0.0 10 | */ 11 | PRINT 'Populating data into [Person].[AddressType]'; 12 | 13 | IF OBJECT_ID('tempdb.dbo.#Person_AddressType') IS NOT NULL DROP TABLE #Person_AddressType; 14 | SELECT * INTO #Person_AddressType FROM [Person].[AddressType] WHERE 0=1; 15 | 16 | INSERT INTO #Person_AddressType 17 | ([AddressTypeID], [Name], [rowguid], [ModifiedDate]) 18 | SELECT CAST([AddressTypeID] AS int) AS [AddressTypeID], [Name], [rowguid], [ModifiedDate] FROM 19 | (VALUES 20 | (1, 'Billing', 'b84f78b1-4efe-4a0e-8cb7-70e9f112f886', '20080430 00:00:00.000') 21 | , (2, 'Home', '41bc2ff6-f0fc-475f-8eb9-cec0805aa0f2', '20080430 00:00:00.000') 22 | , (3, 'Main Office', '8eeec28c-07a2-4fb9-ad0a-42d4a0bbc575', '20080430 00:00:00.000') 23 | , (4, 'Primary', '24cb3088-4345-47c4-86c5-17b535133d1e', '20080430 00:00:00.000') 24 | , (5, 'Shipping', 'b29da3f8-19a3-47da-9daa-15c84f4a83a5', '20080430 00:00:00.000') 25 | , (6, 'Archive', 'a67f238a-5ba2-444b-966c-0467ed9c427f', '20080430 00:00:00.000') 26 | ) as v ([AddressTypeID], [Name], [rowguid], [ModifiedDate]); 27 | 28 | 29 | 30 | WITH cte_data as (SELECT CAST([AddressTypeID] AS int) AS [AddressTypeID], [Name], [rowguid], [ModifiedDate] FROM [#Person_AddressType]) 31 | MERGE [Person].[AddressType] as t 32 | USING cte_data as s 33 | ON t.[AddressTypeID] = s.[AddressTypeID] 34 | WHEN NOT MATCHED BY target THEN 35 | INSERT ([AddressTypeID], [Name], [rowguid], [ModifiedDate]) 36 | VALUES (s.[AddressTypeID], s.[Name], s.[rowguid], s.[ModifiedDate]) 37 | WHEN MATCHED THEN 38 | UPDATE SET 39 | [Name] = s.[Name], [rowguid] = s.[rowguid], [ModifiedDate] = s.[ModifiedDate] 40 | WHEN NOT MATCHED BY source THEN 41 | DELETE 42 | ; 43 | 44 | DROP TABLE #Person_AddressType; 45 | 46 | -- End data of table: [Person].[AddressType] -- 47 | END 48 | GO 49 | -------------------------------------------------------------------------------- /OUTPUT/Person.ContactType.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE [dbo].[Populate_Person_ContactType] 2 | AS 3 | BEGIN 4 | /* 5 | Table's data: [Person].[ContactType] 6 | Data Source: [DEV19].[AdventureWorks2014] 7 | Created on: 18/10/2019 15:02:26 8 | Scripted by: DEV19\Administrator 9 | Generated by Data Script Writer - ver. 2.0.0.0 10 | */ 11 | PRINT 'Populating data into [Person].[ContactType]'; 12 | 13 | IF OBJECT_ID('tempdb.dbo.#Person_ContactType') IS NOT NULL DROP TABLE #Person_ContactType; 14 | SELECT * INTO #Person_ContactType FROM [Person].[ContactType] WHERE 0=1; 15 | 16 | INSERT INTO #Person_ContactType 17 | ([ContactTypeID], [Name], [ModifiedDate]) 18 | SELECT CAST([ContactTypeID] AS int) AS [ContactTypeID], [Name], [ModifiedDate] FROM 19 | (VALUES 20 | (1, 'Accounting Manager', '20080430 00:00:00.000') 21 | , (2, 'Assistant Sales Agent', '20080430 00:00:00.000') 22 | , (3, 'Assistant Sales Representative', '20080430 00:00:00.000') 23 | , (4, 'Coordinator Foreign Markets', '20080430 00:00:00.000') 24 | , (5, 'Export Administrator', '20080430 00:00:00.000') 25 | , (6, 'International Marketing Manager', '20080430 00:00:00.000') 26 | , (7, 'Marketing Assistant', '20080430 00:00:00.000') 27 | , (8, 'Marketing Manager', '20080430 00:00:00.000') 28 | , (9, 'Marketing Representative', '20080430 00:00:00.000') 29 | , (10, 'Order Administrator', '20080430 00:00:00.000') 30 | , (11, 'Owner', '20080430 00:00:00.000') 31 | , (12, 'Owner/Marketing Assistant', '20080430 00:00:00.000') 32 | , (13, 'Product Manager', '20080430 00:00:00.000') 33 | , (14, 'Purchasing Agent', '20080430 00:00:00.000') 34 | , (15, 'Purchasing Manager', '20080430 00:00:00.000') 35 | , (16, 'Regional Account Representative', '20080430 00:00:00.000') 36 | , (17, 'Sales Agent', '20080430 00:00:00.000') 37 | , (18, 'Sales Associate', '20080430 00:00:00.000') 38 | , (19, 'Sales Manager', '20080430 00:00:00.000') 39 | , (20, 'Sales Representative', '20080430 00:00:00.000') 40 | ) as v ([ContactTypeID], [Name], [ModifiedDate]); 41 | 42 | 43 | 44 | WITH cte_data as (SELECT CAST([ContactTypeID] AS int) AS [ContactTypeID], [Name], [ModifiedDate] FROM [#Person_ContactType]) 45 | MERGE [Person].[ContactType] as t 46 | USING cte_data as s 47 | ON t.[ContactTypeID] = s.[ContactTypeID] 48 | WHEN NOT MATCHED BY target THEN 49 | INSERT ([ContactTypeID], [Name], [ModifiedDate]) 50 | VALUES (s.[ContactTypeID], s.[Name], s.[ModifiedDate]) 51 | WHEN MATCHED THEN 52 | UPDATE SET 53 | [Name] = s.[Name], [ModifiedDate] = s.[ModifiedDate] 54 | WHEN NOT MATCHED BY source THEN 55 | DELETE 56 | ; 57 | 58 | DROP TABLE #Person_ContactType; 59 | 60 | -- End data of table: [Person].[ContactType] -- 61 | END 62 | GO 63 | -------------------------------------------------------------------------------- /OUTPUT/Person.PhoneNumberType.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE [data].[Populate_Person_PhoneNumberType] 2 | AS 3 | BEGIN 4 | /* 5 | Table's data: [Person].[PhoneNumberType] 6 | Data Source: [DEV19].[AdventureWorks2014] 7 | Created on: 18/10/2019 15:07:03 8 | Scripted by: DEV19\Administrator 9 | Generated by Data Script Writer - ver. 2.0.0.0 10 | */ 11 | PRINT 'Populating data into [Person].[PhoneNumberType]'; 12 | 13 | IF NOT EXISTS (SELECT TOP (1) * FROM [Person].[PhoneNumberType]) 14 | BEGIN 15 | 16 | ;WITH cte_data 17 | as (SELECT [PhoneNumberTypeID], [Name], [ModifiedDate] FROM 18 | (VALUES 19 | (1, 'Cell', '20171213 13:19:22.273') 20 | , (2, 'Home', '20171213 13:19:22.273') 21 | , (3, 'Work', '20171213 13:19:22.273') 22 | ) as v ([PhoneNumberTypeID], [Name], [ModifiedDate]) 23 | ) 24 | INSERT INTO [Person].[PhoneNumberType] 25 | ([PhoneNumberTypeID], [Name], [ModifiedDate]) 26 | SELECT [PhoneNumberTypeID], [Name], [ModifiedDate] 27 | FROM cte_data; 28 | 29 | END 30 | 31 | -- End data of table: [Person].[PhoneNumberType] -- 32 | END 33 | GO 34 | -------------------------------------------------------------------------------- /OUTPUT/Person.PhoneNumberType_INSERT.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE [data].[Populate_Person_PhoneNumberType] 2 | AS 3 | BEGIN 4 | /* 5 | Table's data: [Person].[PhoneNumberType] 6 | Data Source: [DEV19].[AdventureWorks2014] 7 | Created on: 18/10/2019 15:07:03 8 | Scripted by: DEV19\Administrator 9 | Generated by Data Script Writer - ver. 2.0.0.0 10 | */ 11 | PRINT 'Populating data into [Person].[PhoneNumberType]'; 12 | 13 | IF NOT EXISTS (SELECT TOP (1) * FROM [Person].[PhoneNumberType]) 14 | BEGIN 15 | 16 | ;WITH cte_data 17 | as (SELECT [PhoneNumberTypeID], [Name], [ModifiedDate] FROM 18 | (VALUES 19 | (1, 'Cell', '20171213 13:19:22.273') 20 | , (2, 'Home', '20171213 13:19:22.273') 21 | , (3, 'Work', '20171213 13:19:22.273') 22 | ) as v ([PhoneNumberTypeID], [Name], [ModifiedDate]) 23 | ) 24 | INSERT INTO [Person].[PhoneNumberType] 25 | ([PhoneNumberTypeID], [Name], [ModifiedDate]) 26 | SELECT [PhoneNumberTypeID], [Name], [ModifiedDate] 27 | FROM cte_data; 28 | 29 | END 30 | 31 | -- End data of table: [Person].[PhoneNumberType] -- 32 | END 33 | GO 34 | -------------------------------------------------------------------------------- /OUTPUT/Person.PhoneNumberType_MERGE.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE [data].[Populate_Person_PhoneNumberType] 2 | AS 3 | BEGIN 4 | /* 5 | Table's data: [Person].[PhoneNumberType] 6 | Data Source: [DEV19].[AdventureWorks2014] 7 | Created on: 18/10/2019 15:06:49 8 | Scripted by: DEV19\Administrator 9 | Generated by Data Script Writer - ver. 2.0.0.0 10 | */ 11 | PRINT 'Populating data into [Person].[PhoneNumberType]'; 12 | 13 | IF OBJECT_ID('tempdb.dbo.#Person_PhoneNumberType') IS NOT NULL DROP TABLE #Person_PhoneNumberType; 14 | SELECT * INTO #Person_PhoneNumberType FROM [Person].[PhoneNumberType] WHERE 0=1; 15 | 16 | INSERT INTO #Person_PhoneNumberType 17 | ([PhoneNumberTypeID], [Name], [ModifiedDate]) 18 | SELECT CAST([PhoneNumberTypeID] AS int) AS [PhoneNumberTypeID], [Name], [ModifiedDate] FROM 19 | (VALUES 20 | (1, 'Cell', '20171213 13:19:22.273') 21 | , (2, 'Home', '20171213 13:19:22.273') 22 | , (3, 'Work', '20171213 13:19:22.273') 23 | ) as v ([PhoneNumberTypeID], [Name], [ModifiedDate]); 24 | 25 | 26 | 27 | WITH cte_data as (SELECT CAST([PhoneNumberTypeID] AS int) AS [PhoneNumberTypeID], [Name], [ModifiedDate] FROM [#Person_PhoneNumberType]) 28 | MERGE [Person].[PhoneNumberType] as t 29 | USING cte_data as s 30 | ON t.[PhoneNumberTypeID] = s.[PhoneNumberTypeID] 31 | WHEN NOT MATCHED BY target THEN 32 | INSERT ([PhoneNumberTypeID], [Name], [ModifiedDate]) 33 | VALUES (s.[PhoneNumberTypeID], s.[Name], s.[ModifiedDate]) 34 | WHEN MATCHED THEN 35 | UPDATE SET 36 | [Name] = s.[Name], [ModifiedDate] = s.[ModifiedDate] 37 | WHEN NOT MATCHED BY source THEN 38 | DELETE 39 | ; 40 | 41 | DROP TABLE #Person_PhoneNumberType; 42 | 43 | -- End data of table: [Person].[PhoneNumberType] -- 44 | END 45 | GO 46 | -------------------------------------------------------------------------------- /OUTPUT/Person.PhoneNumberType_MERGE_NEW_ONLY.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE [data].[Populate_Person_PhoneNumberType] 2 | AS 3 | BEGIN 4 | /* 5 | Table's data: [Person].[PhoneNumberType] 6 | Data Source: [DEV19].[AdventureWorks2014] 7 | Created on: 18/10/2019 15:08:00 8 | Scripted by: DEV19\Administrator 9 | Generated by Data Script Writer - ver. 2.0.0.0 10 | */ 11 | PRINT 'Populating data into [Person].[PhoneNumberType]'; 12 | 13 | IF OBJECT_ID('tempdb.dbo.#Person_PhoneNumberType') IS NOT NULL DROP TABLE #Person_PhoneNumberType; 14 | SELECT * INTO #Person_PhoneNumberType FROM [Person].[PhoneNumberType] WHERE 0=1; 15 | 16 | INSERT INTO #Person_PhoneNumberType 17 | ([PhoneNumberTypeID], [Name], [ModifiedDate]) 18 | SELECT CAST([PhoneNumberTypeID] AS int) AS [PhoneNumberTypeID], [Name], [ModifiedDate] FROM 19 | (VALUES 20 | (1, 'Cell', '20171213 13:19:22.273') 21 | , (2, 'Home', '20171213 13:19:22.273') 22 | , (3, 'Work', '20171213 13:19:22.273') 23 | ) as v ([PhoneNumberTypeID], [Name], [ModifiedDate]); 24 | 25 | 26 | 27 | WITH cte_data as (SELECT CAST([PhoneNumberTypeID] AS int) AS [PhoneNumberTypeID], [Name], [ModifiedDate] FROM [#Person_PhoneNumberType]) 28 | MERGE [Person].[PhoneNumberType] as t 29 | USING cte_data as s 30 | ON t.[PhoneNumberTypeID] = s.[PhoneNumberTypeID] 31 | WHEN NOT MATCHED BY target THEN 32 | INSERT ([PhoneNumberTypeID], [Name], [ModifiedDate]) 33 | VALUES (s.[PhoneNumberTypeID], s.[Name], s.[ModifiedDate]) 34 | ; 35 | 36 | DROP TABLE #Person_PhoneNumberType; 37 | 38 | -- End data of table: [Person].[PhoneNumberType] -- 39 | END 40 | GO 41 | -------------------------------------------------------------------------------- /OUTPUT/Person.PhoneNumberType_MERGE_without_DELETE.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE [data].[Populate_Person_PhoneNumberType] 2 | AS 3 | BEGIN 4 | /* 5 | Table's data: [Person].[PhoneNumberType] 6 | Data Source: [DEV19].[AdventureWorks2014] 7 | Created on: 18/10/2019 15:07:40 8 | Scripted by: DEV19\Administrator 9 | Generated by Data Script Writer - ver. 2.0.0.0 10 | */ 11 | PRINT 'Populating data into [Person].[PhoneNumberType]'; 12 | 13 | IF OBJECT_ID('tempdb.dbo.#Person_PhoneNumberType') IS NOT NULL DROP TABLE #Person_PhoneNumberType; 14 | SELECT * INTO #Person_PhoneNumberType FROM [Person].[PhoneNumberType] WHERE 0=1; 15 | 16 | INSERT INTO #Person_PhoneNumberType 17 | ([PhoneNumberTypeID], [Name], [ModifiedDate]) 18 | SELECT CAST([PhoneNumberTypeID] AS int) AS [PhoneNumberTypeID], [Name], [ModifiedDate] FROM 19 | (VALUES 20 | (1, 'Cell', '20171213 13:19:22.273') 21 | , (2, 'Home', '20171213 13:19:22.273') 22 | , (3, 'Work', '20171213 13:19:22.273') 23 | ) as v ([PhoneNumberTypeID], [Name], [ModifiedDate]); 24 | 25 | 26 | 27 | WITH cte_data as (SELECT CAST([PhoneNumberTypeID] AS int) AS [PhoneNumberTypeID], [Name], [ModifiedDate] FROM [#Person_PhoneNumberType]) 28 | MERGE [Person].[PhoneNumberType] as t 29 | USING cte_data as s 30 | ON t.[PhoneNumberTypeID] = s.[PhoneNumberTypeID] 31 | WHEN NOT MATCHED BY target THEN 32 | INSERT ([PhoneNumberTypeID], [Name], [ModifiedDate]) 33 | VALUES (s.[PhoneNumberTypeID], s.[Name], s.[ModifiedDate]) 34 | WHEN MATCHED THEN 35 | UPDATE SET 36 | [Name] = s.[Name], [ModifiedDate] = s.[ModifiedDate] 37 | ; 38 | 39 | DROP TABLE #Person_PhoneNumberType; 40 | 41 | -- End data of table: [Person].[PhoneNumberType] -- 42 | END 43 | GO 44 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace DataScriptWriter 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory); 18 | 19 | Application.EnableVisualStyles(); 20 | Application.SetCompatibleTextRenderingDefault(false); 21 | Application.Run(new frmMain()); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("DataScriptWriter")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("SQLPlayer")] 11 | [assembly: AssemblyProduct("Data Script Writer")] 12 | [assembly: AssemblyCopyright("Copyright © Kamil Nowinski 2018-2021")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("9c5ca943-8e6b-4518-8480-3874c6a000c4")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("2.4.0.0")] 35 | [assembly: AssemblyFileVersion("2.4.0.0")] 36 | -------------------------------------------------------------------------------- /Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace DataScriptWriter.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DataScriptWriter.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 65 | /// 66 | internal static System.Drawing.Icon data_backup { 67 | get { 68 | object obj = ResourceManager.GetObject("data_backup", resourceCulture); 69 | return ((System.Drawing.Icon)(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// Looks up a localized resource of type System.Drawing.Bitmap. 75 | /// 76 | internal static System.Drawing.Bitmap if_connect_established_1721 { 77 | get { 78 | object obj = ResourceManager.GetObject("if_connect_established_1721", resourceCulture); 79 | return ((System.Drawing.Bitmap)(obj)); 80 | } 81 | } 82 | 83 | /// 84 | /// Looks up a localized resource of type System.Drawing.Bitmap. 85 | /// 86 | internal static System.Drawing.Bitmap if_exit_6035 { 87 | get { 88 | object obj = ResourceManager.GetObject("if_exit_6035", resourceCulture); 89 | return ((System.Drawing.Bitmap)(obj)); 90 | } 91 | } 92 | 93 | /// 94 | /// Looks up a localized resource of type System.Drawing.Bitmap. 95 | /// 96 | internal static System.Drawing.Bitmap if_script_lightning_36406 { 97 | get { 98 | object obj = ResourceManager.GetObject("if_script_lightning_36406", resourceCulture); 99 | return ((System.Drawing.Bitmap)(obj)); 100 | } 101 | } 102 | 103 | /// 104 | /// Looks up a localized string similar to DECLARE @Tablename nvarchar(100) = '{0}'; 105 | ///DECLARE @oid BIGINT = ( 106 | ///SELECT o.object_id from sys.objects o 107 | ///INNER JOIN sys.schemas s on s.schema_id = o.schema_id 108 | ///WHERE o.name = parsename(@TableName, 1) and s.name = parsename(@TableName, 2) 109 | ///); 110 | ///WITH cc as ( 111 | /// SELECT c.name as COLUMN_NAME, c.is_identity, c.is_computed 112 | /// FROM sys.objects o 113 | /// INNER JOIN sys.columns c ON c.object_id = o.object_id 114 | /// WHERE o.object_id = @oid 115 | ///) 116 | ///select c.ORDINAL_POSITION, c.COLUMN_NAME, c.DATA_TYPE, co.constrain [rest of string was truncated]";. 117 | /// 118 | internal static string LoadColumnInfo { 119 | get { 120 | return ResourceManager.GetString("LoadColumnInfo", resourceCulture); 121 | } 122 | } 123 | 124 | /// 125 | /// Looks up a localized string similar to DECLARE @Tablename nvarchar(100) = '{0}'; 126 | ///DECLARE @oid BIGINT = ( 127 | ///SELECT o.object_id from sys.objects o 128 | ///INNER JOIN sys.schemas s on s.schema_id = o.schema_id 129 | ///WHERE o.name = parsename(@TableName, 1) and s.name = parsename(@TableName, 2) 130 | ///); 131 | ///WITH cc as ( 132 | /// SELECT c.name as COLUMN_NAME, c.is_identity, c.generated_always_type, c.is_computed 133 | /// from sys.objects o 134 | /// INNER JOIN sys.columns c ON c.object_id = o.object_id 135 | /// WHERE o.object_id = @oid 136 | ///) 137 | ///select c.ORDINAL_POSITION, c.COLUMN_NAME, c. [rest of string was truncated]";. 138 | /// 139 | internal static string LoadColumnInfo2016andLater { 140 | get { 141 | return ResourceManager.GetString("LoadColumnInfo2016andLater", resourceCulture); 142 | } 143 | } 144 | 145 | /// 146 | /// Looks up a localized string similar to ;WITH tbs AS 147 | /// ( 148 | /// SELECT s.name AS SchemaName, 149 | /// t.name AS TableName, 150 | /// p.rows 151 | /// FROM sys.tables t (NOLOCK) 152 | /// INNER JOIN sys.schemas s (NOLOCK) ON s.schema_id = t.schema_id 153 | /// INNER JOIN sys.partitions p (NOLOCK) ON p.object_id = t.object_id 154 | /// WHERE t.is_ms_shipped = 0 and p.index_id <= 1 155 | /// ) 156 | ///SELECT SchemaName, TableName, SUM(rows) AS RowCnt 157 | ///FROM tbs 158 | ///GROUP BY SchemaName, TableName;. 159 | /// 160 | internal static string LoadListOfTables { 161 | get { 162 | return ResourceManager.GetString("LoadListOfTables", resourceCulture); 163 | } 164 | } 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | ..\Resources\if_exit_6035.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 123 | 124 | 125 | ..\Resources\data_backup.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 126 | 127 | 128 | ..\Resources\if_connect_established_1721.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 129 | 130 | 131 | ..\Resources\if_script_lightning_36406.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 132 | 133 | 134 | ;WITH tbs AS 135 | ( 136 | SELECT s.name AS SchemaName, 137 | t.name AS TableName, 138 | p.rows 139 | FROM sys.tables t (NOLOCK) 140 | INNER JOIN sys.schemas s (NOLOCK) ON s.schema_id = t.schema_id 141 | INNER JOIN sys.partitions p (NOLOCK) ON p.object_id = t.object_id 142 | WHERE t.is_ms_shipped = 0 and p.index_id <= 1 143 | ) 144 | SELECT SchemaName, TableName, SUM(rows) AS RowCnt 145 | FROM tbs 146 | GROUP BY SchemaName, TableName; 147 | 148 | 149 | DECLARE @Tablename nvarchar(100) = '{0}'; 150 | DECLARE @oid BIGINT = ( 151 | SELECT o.object_id from sys.objects o 152 | INNER JOIN sys.schemas s on s.schema_id = o.schema_id 153 | WHERE o.name = parsename(@TableName, 1) and s.name = parsename(@TableName, 2) 154 | ); 155 | WITH cc as ( 156 | SELECT c.name as COLUMN_NAME, c.is_identity, c.is_computed 157 | FROM sys.objects o 158 | INNER JOIN sys.columns c ON c.object_id = o.object_id 159 | WHERE o.object_id = @oid 160 | ) 161 | select c.ORDINAL_POSITION, c.COLUMN_NAME, c.DATA_TYPE, co.constraint_type, quotename(c.COLUMN_NAME) as Q_COLUMN_NAME, cc.is_identity 162 | from information_schema.columns c 163 | LEFT JOIN ( 164 | select tc.TABLE_SCHEMA, tc.TABLE_NAME, kcu.COLUMN_NAME, tc.constraint_type 165 | from information_schema.table_constraints tc 166 | join information_schema.key_column_usage kcu on 167 | tc.table_schema = kcu.table_schema and 168 | tc.table_name = kcu.table_name and 169 | tc.constraint_name = kcu.constraint_name 170 | where tc.table_name = parsename(@TableName, 1) and 171 | tc.table_schema = parsename(@TableName, 2) and 172 | tc.constraint_type = 'PRIMARY KEY' 173 | ) as co on co.TABLE_SCHEMA = c.TABLE_SCHEMA and co.TABLE_NAME = c.TABLE_NAME and co.COLUMN_NAME = c.COLUMN_NAME 174 | LEFT JOIN cc ON cc.COLUMN_NAME = c.COLUMN_NAME 175 | where c.table_name = parsename(@TableName, 1) and 176 | c.table_schema = parsename(@TableName, 2) 177 | and cc.is_computed = 0 178 | 179 | 180 | DECLARE @Tablename nvarchar(100) = '{0}'; 181 | DECLARE @oid BIGINT = ( 182 | SELECT o.object_id from sys.objects o 183 | INNER JOIN sys.schemas s on s.schema_id = o.schema_id 184 | WHERE o.name = parsename(@TableName, 1) and s.name = parsename(@TableName, 2) 185 | ); 186 | WITH cc as ( 187 | SELECT c.name as COLUMN_NAME, c.is_identity, c.generated_always_type, c.is_computed 188 | from sys.objects o 189 | INNER JOIN sys.columns c ON c.object_id = o.object_id 190 | WHERE o.object_id = @oid 191 | ) 192 | select c.ORDINAL_POSITION, c.COLUMN_NAME, c.DATA_TYPE, co.constraint_type, quotename(c.COLUMN_NAME) as Q_COLUMN_NAME, cc.is_identity, cc.generated_always_type 193 | from information_schema.columns c 194 | LEFT JOIN ( 195 | select tc.TABLE_SCHEMA, tc.TABLE_NAME, kcu.COLUMN_NAME, tc.constraint_type 196 | from information_schema.table_constraints tc 197 | join information_schema.key_column_usage kcu on 198 | tc.table_schema = kcu.table_schema and 199 | tc.table_name = kcu.table_name and 200 | tc.constraint_name = kcu.constraint_name 201 | where tc.table_name = parsename(@TableName, 1) and 202 | tc.table_schema = parsename(@TableName, 2) and 203 | tc.constraint_type = 'PRIMARY KEY' 204 | ) as co on co.TABLE_SCHEMA = c.TABLE_SCHEMA and co.TABLE_NAME = c.TABLE_NAME and co.COLUMN_NAME = c.COLUMN_NAME 205 | LEFT JOIN cc ON cc.COLUMN_NAME = c.COLUMN_NAME 206 | where c.table_name = parsename(@TableName, 1) 207 | and c.table_schema = parsename(@TableName, 2) 208 | and cc.generated_always_type = 0 209 | and cc.is_computed = 0 210 | 211 | -------------------------------------------------------------------------------- /Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace DataScriptWriter.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.6.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Properties/licenses.licx: -------------------------------------------------------------------------------- 1 | DevExpress.XtraGrid.GridControl, DevExpress.XtraGrid.v13.2, Version=13.2.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a 2 | DevExpress.XtraBars.Ribbon.RibbonControl, DevExpress.XtraBars.v13.2, Version=13.2.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a 3 | DevExpress.XtraEditors.ComboBoxEdit, DevExpress.XtraEditors.v13.2, Version=13.2.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a 4 | DevExpress.XtraEditors.TextEdit, DevExpress.XtraEditors.v13.2, Version=13.2.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a 5 | DevExpress.XtraEditors.Repository.RepositoryItemComboBox, DevExpress.XtraEditors.v13.2, Version=13.2.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a 6 | DevExpress.XtraEditors.Repository.RepositoryItemProgressBar, DevExpress.XtraEditors.v13.2, Version=13.2.15.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Data Script Writer 2 | ### current version: 2.4.0 ([download](https://github.com/Azure-Player/DataScriptWriter/releases/download/v2.4/DataScriptWriter_v2.4.0.zip)) 3 | 4 | # Releases 5 | Releases & Application (binaries) can be downloaded from here: 6 | https://github.com/Azure-Player/DataScriptWriter/releases/ 7 | 8 | # User Manual 9 | Blog post & video: 10 | - [Script and deploy the data for database from SSDT project](https://azureplayer.net/2019/10/script-deploy-the-data-for-database-from-ssdt-project/) 11 | - [SSDT: Scripting static data from SQL Server (video)](https://azureplayer.net/2020/04/ssdt-scripting-static-data-from-sql-server-video/) 12 | 13 | 14 | # Screenshot 15 | ![](./images/data-script-writer-selecting.png) 16 | -------------------------------------------------------------------------------- /RequiredDLL/x64/SqlServerSpatial140.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Player/DataScriptWriter/d24e86a6a413f796f3247f82d84a3b144e81c225/RequiredDLL/x64/SqlServerSpatial140.dll -------------------------------------------------------------------------------- /RequiredDLL/x64/msvcr120.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Player/DataScriptWriter/d24e86a6a413f796f3247f82d84a3b144e81c225/RequiredDLL/x64/msvcr120.dll -------------------------------------------------------------------------------- /RequiredDLL/x86/SqlServerSpatial140.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Player/DataScriptWriter/d24e86a6a413f796f3247f82d84a3b144e81c225/RequiredDLL/x86/SqlServerSpatial140.dll -------------------------------------------------------------------------------- /RequiredDLL/x86/msvcr120.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Player/DataScriptWriter/d24e86a6a413f796f3247f82d84a3b144e81c225/RequiredDLL/x86/msvcr120.dll -------------------------------------------------------------------------------- /Resources/data_backup.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Player/DataScriptWriter/d24e86a6a413f796f3247f82d84a3b144e81c225/Resources/data_backup.ico -------------------------------------------------------------------------------- /Resources/if_Archive_box_data_file_storage_1886362.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Player/DataScriptWriter/d24e86a6a413f796f3247f82d84a3b144e81c225/Resources/if_Archive_box_data_file_storage_1886362.ico -------------------------------------------------------------------------------- /Resources/if_connect_established_1721.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Player/DataScriptWriter/d24e86a6a413f796f3247f82d84a3b144e81c225/Resources/if_connect_established_1721.png -------------------------------------------------------------------------------- /Resources/if_exit_6035.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Player/DataScriptWriter/d24e86a6a413f796f3247f82d84a3b144e81c225/Resources/if_exit_6035.png -------------------------------------------------------------------------------- /Resources/if_script_lightning_36406.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Player/DataScriptWriter/d24e86a6a413f796f3247f82d84a3b144e81c225/Resources/if_script_lightning_36406.png -------------------------------------------------------------------------------- /ScriptObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Data; 7 | 8 | namespace DataScriptWriter 9 | { 10 | public class ScriptObject 11 | { 12 | 13 | private string _schema; 14 | private string _table; 15 | private string _method; 16 | 17 | public ScriptObject(DataRowView row) 18 | { 19 | _schema = Plain(row["schema"].ToString()); 20 | _table = Plain(row["table"].ToString()); 21 | _method = row["method"].ToString(); 22 | } 23 | 24 | private string Plain(string name) 25 | { 26 | return name.Replace("[", "").Replace("]", ""); 27 | } 28 | 29 | public string Schema { get => _schema; } 30 | public string Table { get => _table; } 31 | public string Method { get => _method; } 32 | public string FullName { get => _schema + "." + _table; } 33 | public string FullQuoted { get => "[" + _schema + "].[" + _table + "]"; } 34 | public string TempCounterpart { get => "#" + FullName.Replace(".", "_").Replace(" ", "_"); } 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ScriptWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Data; 7 | using System.IO; 8 | 9 | namespace DataScriptWriter 10 | { 11 | public class ScriptWriter 12 | { 13 | private const int MaxRowsPerBatch = 1000; 14 | private CAMOsoft.DbUtils.MsSqlSession _db = null; 15 | private string _OutputFolder = ""; 16 | private DataRow _ServerInfoRow = null; 17 | private DataTable _dt; 18 | DataView _dv; 19 | public bool OptionProcWrapUp = false; 20 | private string _BatchSeparator = "GO"; 21 | private List _excludeDataTypes = new List(); 22 | 23 | 24 | public ScriptWriter(CAMOsoft.DbUtils.MsSqlSession db, string outputFolder) 25 | { 26 | _db = db; 27 | _OutputFolder = outputFolder; 28 | string sql = "SELECT @@SPID AS SPID, SUSER_NAME() AS UserName, DB_NAME() AS DbName, @@SERVERNAME AS ServerName, @@VERSION as ServerVersion;"; 29 | _ServerInfoRow = _db.SelectRow(sql); 30 | 31 | if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["excludeDataTypes"])) 32 | _excludeDataTypes = new List(ConfigurationManager.AppSettings["excludeDataTypes"].Split(new char[] { ';' })); 33 | 34 | InitTable(); 35 | } 36 | 37 | private void InitTable() 38 | { 39 | _dt = new DataTable(); 40 | _dt.Columns.Add("id", typeof(System.String)); 41 | _dt.Columns.Add("isSelected", typeof(System.Boolean)); 42 | _dt.Columns.Add("schema", typeof(System.String)); 43 | _dt.Columns.Add("table", typeof(System.String)); 44 | _dt.Columns.Add("method", typeof(System.String)); 45 | _dt.Columns.Add("rowcount", typeof(System.Int64)); 46 | _dv = new DataView(_dt, "isSelected=1", "", DataViewRowState.CurrentRows); 47 | } 48 | 49 | 50 | public void LoadListOfTables() 51 | { 52 | string sql = Properties.Resources.ResourceManager.GetString("LoadListOfTables"); 53 | DataTable TableList = _db.SelectTable(sql, "TableList"); 54 | foreach (DataRow dr in TableList.Rows) 55 | { 56 | AddItemToTable(dr["SchemaName"].ToString(), dr["TableName"].ToString(), "MERGE", Int64.Parse(dr["RowCnt"].ToString())); 57 | } 58 | } 59 | 60 | private void AddItemToTable(string schema, string table, string method, long rowCount) 61 | { 62 | DataRow newRow = _dt.NewRow(); 63 | newRow["id"] = String.Format("{0}.{1}", schema, table); 64 | newRow["schema"] = schema; 65 | newRow["table"] = table; 66 | newRow["method"] = method; 67 | newRow["isSelected"] = false; 68 | newRow["rowcount"] = rowCount; 69 | _dt.Rows.Add(newRow); 70 | } 71 | 72 | private string GetColList(DataTable dt, string filter, string format) 73 | { 74 | List cols = new List(); 75 | foreach (DataRow row in dt.Select(filter)) 76 | { 77 | string s = String.Format(format, row["Q_COLUMN_NAME"].ToString()); 78 | cols.Add(s); 79 | } 80 | return String.Join(", ", cols); 81 | } 82 | private string GetColListWithCastForPK(DataTable dt) 83 | { 84 | List cols = new List(); 85 | foreach (DataRow row in dt.Rows) 86 | { 87 | string s = ""; 88 | if (row["constraint_type"].ToString() == "PRIMARY KEY") 89 | s = String.Format("CAST({0} AS {1}) AS {0}", row["Q_COLUMN_NAME"], row["DATA_TYPE"]); 90 | else 91 | s = String.Format("{0}", row["Q_COLUMN_NAME"].ToString()); 92 | cols.Add(s); 93 | } 94 | return String.Join(", ", cols); 95 | } 96 | 97 | private DataTable LoadColumnsInfo(ScriptObject so) 98 | { 99 | string queryDef = "LoadColumnInfo"; 100 | if (IsSQLServer2016orLater()) queryDef = "LoadColumnInfo2016andLater"; 101 | string sql = Properties.Resources.ResourceManager.GetString(queryDef); 102 | sql = sql.Replace("{0}", so.FullName); 103 | DataTable dt = _db.SelectTable(sql, "ColumnInfo"); 104 | string filter = string.Empty; 105 | 106 | if(_excludeDataTypes.Count >= 1) 107 | filter = string.Format("DATA_TYPE NOT in ({0})", string.Join(",", _excludeDataTypes.Select(x => string.Format("'{0}'", x)))); 108 | 109 | var filteredDr = dt.Select(filter); 110 | var filteredDt = new DataTable(); 111 | 112 | if (filteredDr.Length != 0) 113 | filteredDt = filteredDr.CopyToDataTable(); 114 | filteredDt.TableName = dt.TableName; 115 | 116 | return filteredDt; 117 | 118 | } 119 | 120 | private bool IsSQLServer2016orLater() 121 | { 122 | return (this.ServerVersion.StartsWith("Microsoft SQL Azure") || this.ServerVersion.CompareTo("Microsoft SQL Server 2016") > 0); 123 | } 124 | 125 | private StringBuilder SerializeRowValues(DataRow row, DataTable colInfoTable, string prefix, string suffix) 126 | { 127 | StringBuilder sb = new StringBuilder(); 128 | sb.Append(prefix); 129 | bool first = true; 130 | foreach (DataColumn col in row.Table.Columns) 131 | { 132 | if (!first) 133 | { 134 | sb.Append(",\t"); 135 | } 136 | first = false; 137 | string sqltype = colInfoTable.Select("COLUMN_NAME = '" + col.ColumnName + "'")[0]["DATA_TYPE"].ToString(); 138 | string v = ""; 139 | if (row[col] == DBNull.Value) 140 | { 141 | v = "null"; 142 | } 143 | else 144 | { 145 | switch (sqltype) 146 | { 147 | case "uniqueidentifier": 148 | v = "'" + row[col].ToString() + "'"; 149 | break; 150 | case "xml": 151 | v = "'" + row[col].ToString().Replace("'", "''") + "'"; 152 | break; 153 | case "char": 154 | case "varchar": 155 | case "text": 156 | v = "'" + row[col].ToString().Replace("'", "''") + "'"; 157 | break; 158 | case "nchar": 159 | case "nvarchar": 160 | case "ntext": 161 | case "sysname": 162 | v = "N'" + row[col].ToString().Replace("'", "''") + "'"; 163 | break; 164 | case "datetime": 165 | v = String.Format("'{0:yyyyMMdd HH:mm:ss}'", row[col]); //Lack of accuracy! 166 | break; 167 | case "date": 168 | v = String.Format("'{0:yyyyMMdd}'", row[col]); 169 | break; 170 | case "time": 171 | v = String.Format("'{0:HH:mm:ss.fff}'", row[col]); 172 | break; 173 | case "tinyint": 174 | case "int": 175 | case "float": 176 | case "numeric": 177 | case "decimal": 178 | case "smallmoney": 179 | case "money": 180 | case "smallint": 181 | case "real": 182 | case "bigint": 183 | v = String.Format("{0}", row[col]); 184 | break; 185 | case "bit": 186 | v = ((bool)row[col]) == true ? "1" : "0"; 187 | break; 188 | case "binary": 189 | case "varbinary": 190 | v = "0x" + ByteArrayToHex((byte[])row[col]); 191 | break; 192 | case "datetimeoffset": 193 | v = String.Format("'{0:yyyyMMdd HH:mm:ss.fffffff} {1}'", row[col], row[col].ToString().Substring(row[col].ToString().Length - 6)); 194 | break; 195 | default: 196 | throw new Exception("Unknown SQL data type! (" + sqltype + ")"); 197 | } 198 | } 199 | sb.Append(v); 200 | } 201 | sb.Append(suffix); 202 | return sb; 203 | } 204 | 205 | private string ByteArrayToHex(byte[] barray) 206 | { 207 | char[] c = new char[barray.Length * 2]; 208 | byte b; 209 | for (int i = 0; i < barray.Length; ++i) 210 | { 211 | b = ((byte)(barray[i] >> 4)); 212 | c[i * 2] = (char)(b > 9 ? b + 0x37 : b + 0x30); 213 | b = ((byte)(barray[i] & 0xF)); 214 | c[i * 2 + 1] = (char)(b > 9 ? b + 0x37 : b + 0x30); 215 | } 216 | return new string(c); 217 | } 218 | 219 | private string getSelectStatement(DataTable colInfoTable, ScriptObject so) 220 | { 221 | StringBuilder sb = new StringBuilder("SELECT "); 222 | int RowIndex = 0; 223 | foreach (DataRow row in colInfoTable.Rows) 224 | { 225 | string dt = row["DATA_TYPE"].ToString(); 226 | string colName = row["Q_COLUMN_NAME"].ToString(); 227 | switch (dt) 228 | { 229 | case "datetime": 230 | case "datetime2": 231 | sb.AppendFormat("REPLACE(CONVERT(varchar(50), {0}, 121), '-', '') as {0}", colName); 232 | colInfoTable.Columns["DATA_TYPE"].ReadOnly = false; 233 | row["DATA_TYPE"] = "varchar"; 234 | break; 235 | default: 236 | sb.Append(colName); 237 | break; 238 | } 239 | RowIndex++; 240 | if (RowIndex < row.Table.Rows.Count) 241 | sb.Append(", "); 242 | } 243 | sb.Append(" FROM " + so.FullQuoted + ";"); 244 | return sb.ToString(); 245 | } 246 | 247 | private bool hasIdentity(DataTable colInfoTable) 248 | { 249 | return colInfoTable.Select("is_identity = 1").Length > 0; 250 | } 251 | 252 | public void GenerateForTable(ScriptObject so) 253 | { 254 | _BatchSeparator = this.OptionProcWrapUp ? "" : "GO"; 255 | DataTable colInfoTable = LoadColumnsInfo(so); 256 | DataTable mainTable = _db.SelectTable(getSelectStatement(colInfoTable, so), "MainTable"); 257 | 258 | string filename = Path.Combine(_OutputFolder, so.FullName + ".sql"); 259 | System.IO.StreamWriter w = new System.IO.StreamWriter(filename); 260 | 261 | string colList = GetColList(colInfoTable, "", "{0}"); 262 | string colCastList = GetColListWithCastForPK(colInfoTable); 263 | string scolList = GetColList(colInfoTable, "", "s.{0}"); 264 | string PKcolListOn = GetColList(colInfoTable, "constraint_type = 'PRIMARY KEY'", "t.{0} = s.{0}"); 265 | 266 | //SP 267 | if (OptionProcWrapUp) 268 | { 269 | w.WriteLine(String.Format("CREATE PROCEDURE [{0}].[Populate_{1}]", "dbo", so.TempCounterpart.Replace("#", ""))); 270 | w.WriteLine("AS"); 271 | w.WriteLine("BEGIN"); 272 | } 273 | 274 | //Header 275 | w.WriteLine("/*"); 276 | w.WriteLine(String.Format("\tTable's data: {0}", so.FullQuoted)); 277 | w.WriteLine(String.Format("\tData Source: [{0}].[{1}]", ServerName, DbName)); 278 | w.WriteLine(String.Format("\tCreated on: {0}", DateTime.Now)); 279 | w.WriteLine(String.Format("\tScripted by: {0}", UserName)); 280 | w.WriteLine( "\tGenerated by: " + Global.AppName); 281 | w.WriteLine( "\tGitHub repo URL: https://github.com/SQLPlayer/DataScriptWriter/"); 282 | w.WriteLine("*/"); 283 | 284 | //Body 285 | w.WriteLine(String.Format("PRINT 'Populating data into {0}';", so.FullQuoted)); 286 | w.WriteLine(_BatchSeparator); 287 | 288 | switch (so.Method) 289 | { 290 | case "MERGE": 291 | case "MERGE_without_DELETE": 292 | case "MERGE_NEW_ONLY": 293 | ScriptTableMerge(so, colInfoTable, mainTable, w, colList, scolList, PKcolListOn, colCastList); 294 | break; 295 | case "INSERT": 296 | ScriptTableInitialInsert(so, colInfoTable, mainTable, w, colList, scolList, PKcolListOn); 297 | break; 298 | default: 299 | throw new Exception("Unknown method: " + so.Method); 300 | } 301 | 302 | //Footer 303 | w.WriteLine(String.Format("-- End data of table: {0} --", so.FullQuoted)); 304 | if (OptionProcWrapUp) 305 | { 306 | w.WriteLine("END"); 307 | w.WriteLine("GO"); 308 | } 309 | 310 | w.Close(); 311 | Console.WriteLine(so.FullQuoted + " was scripted."); 312 | } 313 | 314 | private void ScriptTableMerge(ScriptObject so, DataTable colInfoTable, DataTable mainTable, System.IO.StreamWriter w, string colList, string scolList, string PKcolListOn, string colCastList) 315 | { 316 | string tmpTableName = so.TempCounterpart; 317 | bool useIdentity = hasIdentity(colInfoTable); 318 | 319 | w.WriteLine(String.Format("IF OBJECT_ID('tempdb.dbo.{0}') IS NOT NULL DROP TABLE {0};", tmpTableName)); 320 | w.WriteLine(String.Format("SELECT {2} INTO {1} FROM {0} WHERE 0=1;", so.FullQuoted, tmpTableName, colList)); 321 | w.WriteLine(_BatchSeparator); 322 | 323 | if (useIdentity) 324 | { 325 | w.WriteLine(String.Format("SET IDENTITY_INSERT {0} ON;", tmpTableName)); 326 | w.WriteLine(_BatchSeparator); 327 | } 328 | 329 | string rowsep = "\t "; 330 | int rowIndex = 0; 331 | foreach (DataRow row in mainTable.Rows) 332 | { 333 | //Begin Insert to temp 334 | if (rowIndex % MaxRowsPerBatch == 0) 335 | { 336 | w.WriteLine(String.Format("INSERT INTO {0} ", tmpTableName)); 337 | w.WriteLine(String.Format(" ({0})", colList)); 338 | w.WriteLine(String.Format("SELECT {0} FROM ", colCastList)); 339 | w.WriteLine("(VALUES"); 340 | rowsep = "\t "; 341 | } 342 | 343 | //VALUES 344 | w.Write(rowsep); 345 | rowsep = "\t, "; 346 | w.WriteLine(SerializeRowValues(row, colInfoTable, "(", ")")); 347 | rowIndex++; 348 | 349 | //End Insert to Temp 350 | if (rowIndex % MaxRowsPerBatch == 0 || rowIndex == mainTable.Rows.Count) 351 | { 352 | w.WriteLine(String.Format(") as v ({0});", colList)); 353 | w.WriteLine(_BatchSeparator); 354 | w.WriteLine(""); 355 | } 356 | } 357 | 358 | //Identity 359 | if (useIdentity) 360 | { 361 | w.WriteLine(String.Format("SET IDENTITY_INSERT {0} OFF;", tmpTableName)); 362 | w.WriteLine(_BatchSeparator); 363 | w.WriteLine(String.Format("SET IDENTITY_INSERT {0} ON;", so.FullQuoted)); 364 | w.WriteLine(_BatchSeparator); 365 | } 366 | 367 | //Begin Merge 368 | w.WriteLine(""); 369 | w.WriteLine(String.Format("WITH cte_data as (SELECT {1} FROM [{0}])", tmpTableName, colCastList)); 370 | w.WriteLine(String.Format("MERGE {0} as t", so.FullQuoted)); 371 | w.WriteLine("USING cte_data as s"); 372 | w.WriteLine(String.Format("\tON {0}", PKcolListOn.Replace(",", " AND"))); 373 | w.WriteLine("WHEN NOT MATCHED BY target THEN"); 374 | w.WriteLine(String.Format("\tINSERT ({0})", colList)); 375 | w.WriteLine(String.Format("\tVALUES ({0})", scolList)); 376 | 377 | //Merge: WHEN MATCHED 378 | if (so.Method != "MERGE_NEW_ONLY") 379 | { 380 | string UpdateColList = GetColList(colInfoTable, "constraint_type IS NULL", "{0} = s.{0}"); 381 | w.WriteLine("WHEN MATCHED THEN "); 382 | w.WriteLine("\tUPDATE SET "); 383 | w.WriteLine(String.Format("\t{0}", UpdateColList)); 384 | } 385 | 386 | //Merge: WHEN NOT MATCHED 387 | if (so.Method == "MERGE") 388 | { 389 | w.WriteLine("WHEN NOT MATCHED BY source THEN"); 390 | w.WriteLine("\tDELETE"); 391 | } 392 | 393 | w.WriteLine(";"); 394 | w.WriteLine(_BatchSeparator); 395 | 396 | //End 397 | if (useIdentity) 398 | { 399 | w.WriteLine(String.Format("SET IDENTITY_INSERT {0} OFF;", so.FullQuoted)); 400 | w.WriteLine(_BatchSeparator); 401 | } 402 | w.WriteLine(String.Format("DROP TABLE {0};", tmpTableName)); 403 | w.WriteLine(_BatchSeparator); 404 | } 405 | 406 | private void ScriptTableInitialInsert(ScriptObject so, DataTable colInfoTable, DataTable mainTable, System.IO.StreamWriter w, string colList, string scolList, string PKcolListOn) 407 | { 408 | bool useIdentity = hasIdentity(colInfoTable); 409 | 410 | //Begin IF 411 | w.WriteLine(String.Format("IF NOT EXISTS (SELECT TOP (1) * FROM {0})", so.FullQuoted)); 412 | w.WriteLine("BEGIN"); 413 | w.WriteLine(""); 414 | if (useIdentity) 415 | { 416 | w.WriteLine(String.Format("\tSET IDENTITY_INSERT {0} ON;", so.FullQuoted)); 417 | w.WriteLine(""); 418 | } 419 | 420 | w.WriteLine("\t;WITH cte_data"); 421 | w.WriteLine(String.Format("\tas (SELECT {0} FROM ", colList)); 422 | w.WriteLine("\t(VALUES"); 423 | 424 | //VALUES 425 | string rowsep = "\t "; 426 | foreach (DataRow row in mainTable.Rows) 427 | { 428 | w.Write(rowsep); 429 | rowsep = "\t, "; 430 | w.WriteLine(SerializeRowValues(row, colInfoTable, "(", ")")); 431 | } 432 | 433 | w.WriteLine(String.Format("\t) as v ({0})", colList)); 434 | w.WriteLine(")"); 435 | 436 | w.WriteLine(String.Format("\tINSERT INTO {0}", so.FullQuoted)); 437 | w.WriteLine(String.Format("\t({0})", colList)); 438 | w.WriteLine(String.Format("\tSELECT {0}", colList)); 439 | w.WriteLine("\tFROM cte_data;"); 440 | 441 | //End 442 | if (useIdentity) 443 | { 444 | w.WriteLine(""); 445 | w.WriteLine(String.Format("\tSET IDENTITY_INSERT {0} OFF;", so.FullQuoted)); 446 | } 447 | 448 | w.WriteLine(""); 449 | w.WriteLine("END"); 450 | w.WriteLine(_BatchSeparator); 451 | } 452 | 453 | 454 | public string OutputFolder 455 | { 456 | get 457 | { 458 | return _OutputFolder; 459 | } 460 | } 461 | 462 | 463 | public string UserName { 464 | get 465 | { 466 | return _ServerInfoRow["UserName"].ToString(); 467 | } 468 | } 469 | public string DbName 470 | { 471 | get 472 | { 473 | return _ServerInfoRow["DbName"].ToString(); 474 | } 475 | } 476 | 477 | public string ServerName 478 | { 479 | get 480 | { 481 | return _ServerInfoRow["ServerName"].ToString(); 482 | } 483 | } 484 | 485 | public string ServerVersion 486 | { 487 | get 488 | { 489 | return _ServerInfoRow["ServerVersion"].ToString(); 490 | } 491 | } 492 | 493 | public DataTable TableList 494 | { 495 | get 496 | { 497 | return _dt; 498 | } 499 | } 500 | 501 | public DataView SelectedItemView 502 | { 503 | get 504 | { 505 | return _dv; 506 | } 507 | } 508 | 509 | } 510 | } 511 | -------------------------------------------------------------------------------- /SqlServerTypes/Loader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace SqlServerTypes 6 | { 7 | /// 8 | /// Utility methods related to CLR Types for SQL Server 9 | /// 10 | public class Utilities 11 | { 12 | [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] 13 | private static extern IntPtr LoadLibrary(string libname); 14 | 15 | /// 16 | /// Loads the required native assemblies for the current architecture (x86 or x64) 17 | /// 18 | /// 19 | /// Root path of the current application. Use Server.MapPath(".") for ASP.NET applications 20 | /// and AppDomain.CurrentDomain.BaseDirectory for desktop applications. 21 | /// 22 | public static void LoadNativeAssemblies(string rootApplicationPath) 23 | { 24 | var nativeBinaryPath = IntPtr.Size > 4 25 | ? Path.Combine(rootApplicationPath, @"SqlServerTypes\x64\") 26 | : Path.Combine(rootApplicationPath, @"SqlServerTypes\x86\"); 27 | 28 | LoadNativeAssembly(nativeBinaryPath, "msvcr120.dll"); 29 | LoadNativeAssembly(nativeBinaryPath, "SqlServerSpatial140.dll"); 30 | } 31 | 32 | private static void LoadNativeAssembly(string nativeBinaryPath, string assemblyName) 33 | { 34 | var path = Path.Combine(nativeBinaryPath, assemblyName); 35 | var ptr = LoadLibrary(path); 36 | if (ptr == IntPtr.Zero) 37 | { 38 | throw new Exception(string.Format( 39 | "Error loading {0} (ErrorCode: {1})", 40 | assemblyName, 41 | Marshal.GetLastWin32Error())); 42 | } 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /SqlServerTypes/readme.htm: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Microsoft.SqlServer.Types 5 | 17 | 18 | 19 |
20 |

Action required to load native assemblies

21 |

22 | To deploy an application that uses spatial data types to a machine that does not have 'System CLR Types for SQL Server' installed you also need to deploy the native assembly SqlServerSpatial140.dll. Both x86 (32 bit) and x64 (64 bit) versions of this assembly have been added to your project under the SqlServerTypes\x86 and SqlServerTypes\x64 subdirectories. The native assembly msvcr120.dll is also included in case the C++ runtime is not installed. 23 |

24 |

25 | You need to add code to load the correct one of these assemblies at runtime (depending on the current architecture). 26 |

27 |

ASP.NET Web Sites

28 |

29 | For ASP.NET Web Sites, add the following block of code to the code behind file of the Web Form where you have added Report Viewer Control: 30 |

31 |     Default.aspx.cs:
32 |         
33 |     public partial class _Default : System.Web.UI.Page
34 |     {
35 |         static bool _isSqlTypesLoaded = false;
36 | 
37 |         public _Default()
38 |         {
39 |             if (!_isSqlTypesLoaded)
40 |             {
41 |                 SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~"));
42 |                 _isSqlTypesLoaded = true;
43 |             }
44 |             
45 |         }
46 |     }
47 | 
48 |

49 |

ASP.NET Web Applications

50 |

51 | For ASP.NET Web Applications, add the following line of code to the Application_Start method in Global.asax.cs: 52 |

    SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
53 |

54 |

Desktop Applications

55 |

56 | For desktop applications, add the following line of code to run before any spatial operations are performed: 57 |

    SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
58 |

59 |
60 | 61 | -------------------------------------------------------------------------------- /frmMain.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace DataScriptWriter 2 | { 3 | partial class frmMain 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMain)); 32 | this.gridControl1 = new DevExpress.XtraGrid.GridControl(); 33 | this.gridView1 = new DevExpress.XtraGrid.Views.Grid.GridView(); 34 | this.isSelected = new DevExpress.XtraGrid.Columns.GridColumn(); 35 | this.id = new DevExpress.XtraGrid.Columns.GridColumn(); 36 | this.gcSchema = new DevExpress.XtraGrid.Columns.GridColumn(); 37 | this.gcTable = new DevExpress.XtraGrid.Columns.GridColumn(); 38 | this.gcMethod = new DevExpress.XtraGrid.Columns.GridColumn(); 39 | this.repositoryItemComboBox1 = new DevExpress.XtraEditors.Repository.RepositoryItemComboBox(); 40 | this.gcRows = new DevExpress.XtraGrid.Columns.GridColumn(); 41 | this.ribbonStatusBar1 = new DevExpress.XtraBars.Ribbon.RibbonStatusBar(); 42 | this.barStaticItem4 = new DevExpress.XtraBars.BarStaticItem(); 43 | this.bsiCount = new DevExpress.XtraBars.BarStaticItem(); 44 | this.barStaticItem1 = new DevExpress.XtraBars.BarStaticItem(); 45 | this.bsiDatabaseName = new DevExpress.XtraBars.BarStaticItem(); 46 | this.progress = new DevExpress.XtraBars.BarEditItem(); 47 | this.repositoryItemProgressBar1 = new DevExpress.XtraEditors.Repository.RepositoryItemProgressBar(); 48 | this.ribbonControl1 = new DevExpress.XtraBars.Ribbon.RibbonControl(); 49 | this.bbiConnect = new DevExpress.XtraBars.BarButtonItem(); 50 | this.bbiExit = new DevExpress.XtraBars.BarButtonItem(); 51 | this.bbiScript = new DevExpress.XtraBars.BarButtonItem(); 52 | this.bbiSettings = new DevExpress.XtraBars.BarButtonItem(); 53 | this.bbiCopyDb = new DevExpress.XtraBars.BarButtonItem(); 54 | this.rpHome = new DevExpress.XtraBars.Ribbon.RibbonPage(); 55 | this.ribbonPageGroup1 = new DevExpress.XtraBars.Ribbon.RibbonPageGroup(); 56 | this.barButtonItem1 = new DevExpress.XtraBars.BarButtonItem(); 57 | this.barStaticItem2 = new DevExpress.XtraBars.BarStaticItem(); 58 | this.barStaticItem3 = new DevExpress.XtraBars.BarStaticItem(); 59 | this.ribbonPageGroup2 = new DevExpress.XtraBars.Ribbon.RibbonPageGroup(); 60 | ((System.ComponentModel.ISupportInitialize)(this.gridControl1)).BeginInit(); 61 | ((System.ComponentModel.ISupportInitialize)(this.gridView1)).BeginInit(); 62 | ((System.ComponentModel.ISupportInitialize)(this.repositoryItemComboBox1)).BeginInit(); 63 | ((System.ComponentModel.ISupportInitialize)(this.repositoryItemProgressBar1)).BeginInit(); 64 | ((System.ComponentModel.ISupportInitialize)(this.ribbonControl1)).BeginInit(); 65 | this.SuspendLayout(); 66 | // 67 | // gridControl1 68 | // 69 | this.gridControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 70 | | System.Windows.Forms.AnchorStyles.Left) 71 | | System.Windows.Forms.AnchorStyles.Right))); 72 | this.gridControl1.Location = new System.Drawing.Point(0, 119); 73 | this.gridControl1.MainView = this.gridView1; 74 | this.gridControl1.Name = "gridControl1"; 75 | this.gridControl1.RepositoryItems.AddRange(new DevExpress.XtraEditors.Repository.RepositoryItem[] { 76 | this.repositoryItemComboBox1}); 77 | this.gridControl1.Size = new System.Drawing.Size(928, 474); 78 | this.gridControl1.TabIndex = 18; 79 | this.gridControl1.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] { 80 | this.gridView1}); 81 | this.gridControl1.DoubleClick += new System.EventHandler(this.gridControl1_DoubleClick); 82 | // 83 | // gridView1 84 | // 85 | this.gridView1.Columns.AddRange(new DevExpress.XtraGrid.Columns.GridColumn[] { 86 | this.isSelected, 87 | this.id, 88 | this.gcSchema, 89 | this.gcTable, 90 | this.gcMethod, 91 | this.gcRows}); 92 | this.gridView1.GridControl = this.gridControl1; 93 | this.gridView1.Name = "gridView1"; 94 | this.gridView1.OptionsBehavior.AllowAddRows = DevExpress.Utils.DefaultBoolean.False; 95 | this.gridView1.OptionsBehavior.AllowDeleteRows = DevExpress.Utils.DefaultBoolean.False; 96 | this.gridView1.OptionsView.ShowAutoFilterRow = true; 97 | this.gridView1.OptionsView.ShowFilterPanelMode = DevExpress.XtraGrid.Views.Base.ShowFilterPanelMode.ShowAlways; 98 | this.gridView1.RowUpdated += new DevExpress.XtraGrid.Views.Base.RowObjectEventHandler(this.gridView1_RowUpdated); 99 | // 100 | // isSelected 101 | // 102 | this.isSelected.Caption = "S"; 103 | this.isSelected.FieldName = "isSelected"; 104 | this.isSelected.Name = "isSelected"; 105 | this.isSelected.Visible = true; 106 | this.isSelected.VisibleIndex = 0; 107 | this.isSelected.Width = 68; 108 | // 109 | // id 110 | // 111 | this.id.Caption = "id"; 112 | this.id.FieldName = "id"; 113 | this.id.Name = "id"; 114 | this.id.OptionsColumn.AllowEdit = false; 115 | // 116 | // gcSchema 117 | // 118 | this.gcSchema.Caption = "Schema Name"; 119 | this.gcSchema.FieldName = "schema"; 120 | this.gcSchema.Name = "gcSchema"; 121 | this.gcSchema.OptionsColumn.AllowEdit = false; 122 | this.gcSchema.Visible = true; 123 | this.gcSchema.VisibleIndex = 1; 124 | this.gcSchema.Width = 274; 125 | // 126 | // gcTable 127 | // 128 | this.gcTable.Caption = "Table Name"; 129 | this.gcTable.FieldName = "table"; 130 | this.gcTable.Name = "gcTable"; 131 | this.gcTable.OptionsColumn.AllowEdit = false; 132 | this.gcTable.Visible = true; 133 | this.gcTable.VisibleIndex = 2; 134 | this.gcTable.Width = 274; 135 | // 136 | // gcMethod 137 | // 138 | this.gcMethod.Caption = "Method"; 139 | this.gcMethod.ColumnEdit = this.repositoryItemComboBox1; 140 | this.gcMethod.FieldName = "method"; 141 | this.gcMethod.Name = "gcMethod"; 142 | this.gcMethod.Visible = true; 143 | this.gcMethod.VisibleIndex = 3; 144 | this.gcMethod.Width = 277; 145 | // 146 | // repositoryItemComboBox1 147 | // 148 | this.repositoryItemComboBox1.AutoHeight = false; 149 | this.repositoryItemComboBox1.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { 150 | new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)}); 151 | this.repositoryItemComboBox1.Items.AddRange(new object[] { 152 | "INSERT", 153 | "MERGE", 154 | "MERGE_without_DELETE", 155 | "MERGE_NEW_ONLY"}); 156 | this.repositoryItemComboBox1.Name = "repositoryItemComboBox1"; 157 | // 158 | // gcRows 159 | // 160 | this.gcRows.Caption = "# rows"; 161 | this.gcRows.DisplayFormat.FormatString = "# ### ### ##0"; 162 | this.gcRows.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric; 163 | this.gcRows.FieldName = "rowcount"; 164 | this.gcRows.Name = "gcRows"; 165 | this.gcRows.OptionsColumn.AllowEdit = false; 166 | this.gcRows.Visible = true; 167 | this.gcRows.VisibleIndex = 4; 168 | // 169 | // ribbonStatusBar1 170 | // 171 | this.ribbonStatusBar1.ItemLinks.Add(this.barStaticItem4); 172 | this.ribbonStatusBar1.ItemLinks.Add(this.bsiCount); 173 | this.ribbonStatusBar1.ItemLinks.Add(this.barStaticItem1); 174 | this.ribbonStatusBar1.ItemLinks.Add(this.bsiDatabaseName); 175 | this.ribbonStatusBar1.ItemLinks.Add(this.progress); 176 | this.ribbonStatusBar1.Location = new System.Drawing.Point(0, 594); 177 | this.ribbonStatusBar1.Name = "ribbonStatusBar1"; 178 | this.ribbonStatusBar1.Ribbon = this.ribbonControl1; 179 | this.ribbonStatusBar1.Size = new System.Drawing.Size(928, 27); 180 | // 181 | // barStaticItem4 182 | // 183 | this.barStaticItem4.Caption = "Selected/All:"; 184 | this.barStaticItem4.Glyph = ((System.Drawing.Image)(resources.GetObject("barStaticItem4.Glyph"))); 185 | this.barStaticItem4.Id = 8; 186 | this.barStaticItem4.LargeGlyph = ((System.Drawing.Image)(resources.GetObject("barStaticItem4.LargeGlyph"))); 187 | this.barStaticItem4.Name = "barStaticItem4"; 188 | this.barStaticItem4.TextAlignment = System.Drawing.StringAlignment.Near; 189 | // 190 | // bsiCount 191 | // 192 | this.bsiCount.Caption = "0/0"; 193 | this.bsiCount.Id = 9; 194 | this.bsiCount.Name = "bsiCount"; 195 | this.bsiCount.TextAlignment = System.Drawing.StringAlignment.Near; 196 | // 197 | // barStaticItem1 198 | // 199 | this.barStaticItem1.Caption = "Wait"; 200 | this.barStaticItem1.Glyph = ((System.Drawing.Image)(resources.GetObject("barStaticItem1.Glyph"))); 201 | this.barStaticItem1.Id = 1; 202 | this.barStaticItem1.LargeGlyph = ((System.Drawing.Image)(resources.GetObject("barStaticItem1.LargeGlyph"))); 203 | this.barStaticItem1.Name = "barStaticItem1"; 204 | this.barStaticItem1.TextAlignment = System.Drawing.StringAlignment.Near; 205 | // 206 | // bsiDatabaseName 207 | // 208 | this.bsiDatabaseName.Alignment = DevExpress.XtraBars.BarItemLinkAlignment.Right; 209 | this.bsiDatabaseName.Caption = "(database)"; 210 | this.bsiDatabaseName.Glyph = ((System.Drawing.Image)(resources.GetObject("bsiDatabaseName.Glyph"))); 211 | this.bsiDatabaseName.Id = 2; 212 | this.bsiDatabaseName.LargeGlyph = ((System.Drawing.Image)(resources.GetObject("bsiDatabaseName.LargeGlyph"))); 213 | this.bsiDatabaseName.Name = "bsiDatabaseName"; 214 | this.bsiDatabaseName.TextAlignment = System.Drawing.StringAlignment.Near; 215 | // 216 | // progress 217 | // 218 | this.progress.Caption = "Progress:"; 219 | this.progress.Edit = this.repositoryItemProgressBar1; 220 | this.progress.Id = 3; 221 | this.progress.Name = "progress"; 222 | this.progress.Width = 100; 223 | // 224 | // repositoryItemProgressBar1 225 | // 226 | this.repositoryItemProgressBar1.Name = "repositoryItemProgressBar1"; 227 | // 228 | // ribbonControl1 229 | // 230 | this.ribbonControl1.AllowMdiChildButtons = false; 231 | this.ribbonControl1.ApplicationButtonText = "ABC"; 232 | this.ribbonControl1.ExpandCollapseItem.Id = 0; 233 | this.ribbonControl1.Items.AddRange(new DevExpress.XtraBars.BarItem[] { 234 | this.ribbonControl1.ExpandCollapseItem, 235 | this.bbiConnect, 236 | this.bbiExit, 237 | this.barStaticItem4, 238 | this.bsiCount, 239 | this.bbiScript, 240 | this.barStaticItem1, 241 | this.bsiDatabaseName, 242 | this.bbiSettings, 243 | this.bbiCopyDb, 244 | this.progress}); 245 | this.ribbonControl1.Location = new System.Drawing.Point(0, 0); 246 | this.ribbonControl1.MaxItemId = 4; 247 | this.ribbonControl1.Name = "ribbonControl1"; 248 | this.ribbonControl1.Pages.AddRange(new DevExpress.XtraBars.Ribbon.RibbonPage[] { 249 | this.rpHome}); 250 | this.ribbonControl1.RepositoryItems.AddRange(new DevExpress.XtraEditors.Repository.RepositoryItem[] { 251 | this.repositoryItemProgressBar1}); 252 | this.ribbonControl1.ShowApplicationButton = DevExpress.Utils.DefaultBoolean.False; 253 | this.ribbonControl1.ShowExpandCollapseButton = DevExpress.Utils.DefaultBoolean.False; 254 | this.ribbonControl1.ShowPageHeadersMode = DevExpress.XtraBars.Ribbon.ShowPageHeadersMode.Hide; 255 | this.ribbonControl1.ShowToolbarCustomizeItem = false; 256 | this.ribbonControl1.Size = new System.Drawing.Size(928, 121); 257 | this.ribbonControl1.StatusBar = this.ribbonStatusBar1; 258 | this.ribbonControl1.Toolbar.ShowCustomizeItem = false; 259 | this.ribbonControl1.ToolbarLocation = DevExpress.XtraBars.Ribbon.RibbonQuickAccessToolbarLocation.Above; 260 | // 261 | // bbiConnect 262 | // 263 | this.bbiConnect.Caption = "Connect"; 264 | this.bbiConnect.Id = 5; 265 | this.bbiConnect.LargeGlyph = global::DataScriptWriter.Properties.Resources.if_connect_established_1721; 266 | this.bbiConnect.Name = "bbiConnect"; 267 | this.bbiConnect.RibbonStyle = DevExpress.XtraBars.Ribbon.RibbonItemStyles.Large; 268 | this.bbiConnect.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.bbiConnect_ItemClick); 269 | // 270 | // bbiExit 271 | // 272 | this.bbiExit.Caption = "Close app"; 273 | this.bbiExit.Glyph = global::DataScriptWriter.Properties.Resources.if_exit_6035; 274 | this.bbiExit.Id = 6; 275 | this.bbiExit.Name = "bbiExit"; 276 | this.bbiExit.RibbonStyle = DevExpress.XtraBars.Ribbon.RibbonItemStyles.Large; 277 | this.bbiExit.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.bbiExit_ItemClick); 278 | // 279 | // bbiScript 280 | // 281 | this.bbiScript.Caption = "Generate Script"; 282 | this.bbiScript.Id = 10; 283 | this.bbiScript.LargeGlyph = global::DataScriptWriter.Properties.Resources.if_script_lightning_36406; 284 | this.bbiScript.Name = "bbiScript"; 285 | this.bbiScript.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.bbiScript_ItemClick); 286 | // 287 | // bbiSettings 288 | // 289 | this.bbiSettings.Caption = "Settings"; 290 | this.bbiSettings.Glyph = ((System.Drawing.Image)(resources.GetObject("bbiSettings.Glyph"))); 291 | this.bbiSettings.Id = 1; 292 | this.bbiSettings.LargeGlyph = ((System.Drawing.Image)(resources.GetObject("bbiSettings.LargeGlyph"))); 293 | this.bbiSettings.Name = "bbiSettings"; 294 | this.bbiSettings.Visibility = DevExpress.XtraBars.BarItemVisibility.Never; 295 | // 296 | // bbiCopyDb 297 | // 298 | this.bbiCopyDb.Caption = "Copy database"; 299 | this.bbiCopyDb.Glyph = ((System.Drawing.Image)(resources.GetObject("bbiCopyDb.Glyph"))); 300 | this.bbiCopyDb.Id = 2; 301 | this.bbiCopyDb.LargeGlyph = ((System.Drawing.Image)(resources.GetObject("bbiCopyDb.LargeGlyph"))); 302 | this.bbiCopyDb.Name = "bbiCopyDb"; 303 | this.bbiCopyDb.Visibility = DevExpress.XtraBars.BarItemVisibility.Never; 304 | this.bbiCopyDb.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.bbiCopyDb_ItemClick); 305 | // 306 | // rpHome 307 | // 308 | this.rpHome.Groups.AddRange(new DevExpress.XtraBars.Ribbon.RibbonPageGroup[] { 309 | this.ribbonPageGroup1}); 310 | this.rpHome.Name = "rpHome"; 311 | this.rpHome.Text = "Home"; 312 | // 313 | // ribbonPageGroup1 314 | // 315 | this.ribbonPageGroup1.ItemLinks.Add(this.bbiConnect); 316 | this.ribbonPageGroup1.ItemLinks.Add(this.bbiScript); 317 | this.ribbonPageGroup1.ItemLinks.Add(this.bbiSettings); 318 | this.ribbonPageGroup1.ItemLinks.Add(this.bbiCopyDb); 319 | this.ribbonPageGroup1.ItemLinks.Add(this.bbiExit); 320 | this.ribbonPageGroup1.Name = "ribbonPageGroup1"; 321 | this.ribbonPageGroup1.Text = "Operation"; 322 | // 323 | // barButtonItem1 324 | // 325 | this.barButtonItem1.Id = -1; 326 | this.barButtonItem1.Name = "barButtonItem1"; 327 | this.barButtonItem1.RibbonStyle = DevExpress.XtraBars.Ribbon.RibbonItemStyles.Large; 328 | // 329 | // barStaticItem2 330 | // 331 | this.barStaticItem2.Id = -1; 332 | this.barStaticItem2.Name = "barStaticItem2"; 333 | this.barStaticItem2.TextAlignment = System.Drawing.StringAlignment.Near; 334 | // 335 | // barStaticItem3 336 | // 337 | this.barStaticItem3.Caption = "Selected"; 338 | this.barStaticItem3.Id = -1; 339 | this.barStaticItem3.Name = "barStaticItem3"; 340 | this.barStaticItem3.TextAlignment = System.Drawing.StringAlignment.Near; 341 | // 342 | // ribbonPageGroup2 343 | // 344 | this.ribbonPageGroup2.ItemLinks.Add(this.bbiConnect); 345 | this.ribbonPageGroup2.ItemLinks.Add(this.bbiScript); 346 | this.ribbonPageGroup2.ItemLinks.Add(this.bbiExit); 347 | this.ribbonPageGroup2.Name = "ribbonPageGroup2"; 348 | this.ribbonPageGroup2.Text = "Operation"; 349 | // 350 | // frmMain 351 | // 352 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 353 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 354 | this.ClientSize = new System.Drawing.Size(928, 621); 355 | this.Controls.Add(this.ribbonControl1); 356 | this.Controls.Add(this.ribbonStatusBar1); 357 | this.Controls.Add(this.gridControl1); 358 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); 359 | this.MinimumSize = new System.Drawing.Size(724, 400); 360 | this.Name = "frmMain"; 361 | this.Text = "SQLPlayer Data Script Writer"; 362 | ((System.ComponentModel.ISupportInitialize)(this.gridControl1)).EndInit(); 363 | ((System.ComponentModel.ISupportInitialize)(this.gridView1)).EndInit(); 364 | ((System.ComponentModel.ISupportInitialize)(this.repositoryItemComboBox1)).EndInit(); 365 | ((System.ComponentModel.ISupportInitialize)(this.repositoryItemProgressBar1)).EndInit(); 366 | ((System.ComponentModel.ISupportInitialize)(this.ribbonControl1)).EndInit(); 367 | this.ResumeLayout(false); 368 | this.PerformLayout(); 369 | 370 | } 371 | 372 | #endregion 373 | private DevExpress.XtraGrid.GridControl gridControl1; 374 | private DevExpress.XtraGrid.Views.Grid.GridView gridView1; 375 | private DevExpress.XtraGrid.Columns.GridColumn gcSchema; 376 | private DevExpress.XtraGrid.Columns.GridColumn gcTable; 377 | private DevExpress.XtraGrid.Columns.GridColumn gcMethod; 378 | private DevExpress.XtraEditors.Repository.RepositoryItemComboBox repositoryItemComboBox1; 379 | private DevExpress.XtraBars.Ribbon.RibbonStatusBar ribbonStatusBar1; 380 | private DevExpress.XtraGrid.Columns.GridColumn isSelected; 381 | private DevExpress.XtraBars.Ribbon.RibbonControl ribbonControl1; 382 | private DevExpress.XtraBars.Ribbon.RibbonPage rpHome; 383 | private DevExpress.XtraBars.Ribbon.RibbonPageGroup ribbonPageGroup1; 384 | private DevExpress.XtraBars.BarButtonItem bbiConnect; 385 | private DevExpress.XtraBars.BarButtonItem barButtonItem1; 386 | private DevExpress.XtraBars.BarStaticItem barStaticItem2; 387 | private DevExpress.XtraBars.BarStaticItem barStaticItem3; 388 | private DevExpress.XtraBars.BarButtonItem bbiExit; 389 | private DevExpress.XtraBars.BarStaticItem barStaticItem4; 390 | private DevExpress.XtraBars.BarStaticItem bsiCount; 391 | private DevExpress.XtraBars.BarButtonItem bbiScript; 392 | private DevExpress.XtraBars.BarStaticItem barStaticItem1; 393 | private DevExpress.XtraGrid.Columns.GridColumn gcRows; 394 | private DevExpress.XtraGrid.Columns.GridColumn id; 395 | private DevExpress.XtraBars.BarStaticItem bsiDatabaseName; 396 | private DevExpress.XtraBars.Ribbon.RibbonPageGroup ribbonPageGroup2; 397 | private DevExpress.XtraBars.BarButtonItem bbiSettings; 398 | private DevExpress.XtraBars.BarButtonItem bbiCopyDb; 399 | private DevExpress.XtraBars.BarEditItem progress; 400 | private DevExpress.XtraEditors.Repository.RepositoryItemProgressBar repositoryItemProgressBar1; 401 | } 402 | } 403 | 404 | -------------------------------------------------------------------------------- /frmMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Text; 5 | using System.Windows.Forms; 6 | using System.Reflection; 7 | using System.Diagnostics; 8 | 9 | namespace DataScriptWriter 10 | { 11 | public partial class frmMain : DevExpress.XtraBars.Ribbon.RibbonForm 12 | { 13 | ScriptWriter _gen = null; 14 | string _OutputFolder = ""; 15 | 16 | public frmMain() 17 | { 18 | InitializeComponent(); 19 | 20 | Assembly assembly = Assembly.GetExecutingAssembly(); 21 | AssemblyName name = new AssemblyName(assembly.FullName); 22 | FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); 23 | Global.AppName = String.Format("{0} - ver. {1}", fileVersionInfo.ProductName, fileVersionInfo.ProductVersion); 24 | this.Text = Global.AppName; 25 | 26 | _OutputFolder = System.IO.Path.GetDirectoryName(Application.ExecutablePath); 27 | } 28 | 29 | private void btnConnect_Click(object sender, EventArgs e) 30 | { 31 | Connect(); 32 | } 33 | 34 | private void Connect() 35 | { 36 | ConnectDbForm f = new ConnectDbForm("SQLPlayer", "Data Script Writer"); 37 | f.ShowDialog(); 38 | if (f.DialogResult == DialogResult.OK) 39 | { 40 | _gen = new ScriptWriter(f.Db, _OutputFolder); 41 | _gen.OptionProcWrapUp = true; 42 | _gen.LoadListOfTables(); 43 | gridControl1.DataSource = _gen.TableList; 44 | bsiDatabaseName.Caption = _gen.DbName; 45 | } 46 | } 47 | 48 | private void bbiExit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) 49 | { 50 | this.Close(); 51 | } 52 | 53 | private void bbiConnect_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) 54 | { 55 | Connect(); 56 | } 57 | 58 | private void gridView1_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) 59 | { 60 | int AllCount = _gen.TableList.Rows.Count; 61 | int SelectedCount = _gen.SelectedItemView.Count; 62 | bsiCount.Caption = String.Format("{0}/{1}", SelectedCount, AllCount); 63 | } 64 | 65 | private void bbiScript_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) 66 | { 67 | int cnt = 0; 68 | foreach (DataRowView item in _gen.SelectedItemView) 69 | { 70 | ScriptObject so = new ScriptObject(item); 71 | barStaticItem1.Caption = "Scripting: " + so.FullQuoted; 72 | this.Refresh(); 73 | _gen.GenerateForTable(so); 74 | cnt++; 75 | } 76 | barStaticItem1.Caption = String.Format("Done. {0} tables were scripted.", cnt); 77 | DialogResult r = MessageBox.Show( "Do you want to open target location with File Explorer?", "Open target location", MessageBoxButtons.YesNo); 78 | if (r == DialogResult.Yes) 79 | { 80 | Process.Start("explorer.exe", _gen.OutputFolder); 81 | } 82 | } 83 | 84 | private void gridControl1_DoubleClick(object sender, EventArgs e) 85 | { 86 | } 87 | 88 | private void bbiCopyDb_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) 89 | { 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /frmNoteForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace DataScriptWriter 2 | { 3 | partial class frmNoteForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.textBox1 = new System.Windows.Forms.TextBox(); 32 | this.btnOK = new System.Windows.Forms.Button(); 33 | this.label1 = new System.Windows.Forms.Label(); 34 | this.SuspendLayout(); 35 | // 36 | // textBox1 37 | // 38 | this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 39 | | System.Windows.Forms.AnchorStyles.Left) 40 | | System.Windows.Forms.AnchorStyles.Right))); 41 | this.textBox1.Location = new System.Drawing.Point(12, 35); 42 | this.textBox1.Multiline = true; 43 | this.textBox1.Name = "textBox1"; 44 | this.textBox1.Size = new System.Drawing.Size(503, 341); 45 | this.textBox1.TabIndex = 0; 46 | // 47 | // btnOK 48 | // 49 | this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 50 | this.btnOK.Location = new System.Drawing.Point(440, 382); 51 | this.btnOK.Name = "btnOK"; 52 | this.btnOK.Size = new System.Drawing.Size(75, 23); 53 | this.btnOK.TabIndex = 1; 54 | this.btnOK.Text = "OK"; 55 | this.btnOK.UseVisualStyleBackColor = true; 56 | this.btnOK.Click += new System.EventHandler(this.btnOK_Click); 57 | // 58 | // label1 59 | // 60 | this.label1.AutoSize = true; 61 | this.label1.Location = new System.Drawing.Point(12, 13); 62 | this.label1.Name = "label1"; 63 | this.label1.Size = new System.Drawing.Size(265, 13); 64 | this.label1.TabIndex = 2; 65 | this.label1.Text = "Just PASTE list of tables below: (each line is one table)"; 66 | // 67 | // frmNoteForm 68 | // 69 | this.AcceptButton = this.btnOK; 70 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 71 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 72 | this.ClientSize = new System.Drawing.Size(527, 413); 73 | this.Controls.Add(this.label1); 74 | this.Controls.Add(this.btnOK); 75 | this.Controls.Add(this.textBox1); 76 | this.Name = "frmNoteForm"; 77 | this.Text = "Note"; 78 | this.ResumeLayout(false); 79 | this.PerformLayout(); 80 | 81 | } 82 | 83 | #endregion 84 | 85 | private System.Windows.Forms.TextBox textBox1; 86 | private System.Windows.Forms.Button btnOK; 87 | private System.Windows.Forms.Label label1; 88 | } 89 | } -------------------------------------------------------------------------------- /frmNoteForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | 11 | namespace DataScriptWriter 12 | { 13 | public partial class frmNoteForm : Form 14 | { 15 | public frmNoteForm() 16 | { 17 | InitializeComponent(); 18 | } 19 | 20 | private void btnOK_Click(object sender, EventArgs e) 21 | { 22 | this.DialogResult = System.Windows.Forms.DialogResult.OK; 23 | this.Hide(); 24 | } 25 | 26 | public string[] Lines { 27 | get 28 | { 29 | return this.textBox1.Lines; 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /frmNoteForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /images/data-script-writer-selecting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Player/DataScriptWriter/d24e86a6a413f796f3247f82d84a3b144e81c225/images/data-script-writer-selecting.png -------------------------------------------------------------------------------- /packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | --------------------------------------------------------------------------------