Commit 1034595599a91ea0f088717fe9861a2f27549ab6
1 parent
7cdc4aa4
v1.25.1.0
- LastUpdate trigger létrehozásában formai változtatások, pontosítások
Showing
2 changed files
with
55 additions
and
36 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs
... | ... | @@ -53,8 +53,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS |
53 | 53 | .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.ExecuteScript.KEY, "Execute script", ExecuteScript, ep)) |
54 | 54 | .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.CreateLoginAndUser.KEY, "Create Server login and database user", CreteLoginAndAddToDB, ep)) |
55 | 55 | .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.AddUserForLogin.KEY, "Add database user to an existing Login", AddExistingLoginToDB, ep)) |
56 | - .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.CreateLastUpdatedTrigger.KEY, "Add LastUpdated trigger to a datatable column", CreateLastUpdatedTrigger, ep)) | |
57 | - .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.RemoveLastUpdatedTrigger.KEY, "Add LastUpdated trigger to a datatable column", RemoveLastUpdatedTrigger, ep)) | |
56 | + .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.Function.CreateLastUpdatedTrigger.KEY, "Add/remove LastUpdated trigger to a datatable column", ManageLastUpdatedTrigger, ep)) | |
58 | 57 | .SetSelectionMode(Menu.SelectionMode.Single) |
59 | 58 | .SetMenuHeaderDisplayer(DataBaseListDisplayer); |
60 | 59 | menufunctions.ExecuteMenu(functionkey); |
... | ... | @@ -228,8 +227,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS |
228 | 227 | private static object CreteLoginAndAddToDB(object parameter, object o) { return _CreteLoginAndUser(parameter, o, true); } |
229 | 228 | private static object AddExistingLoginToDB(object parameter, object o) { return _CreteLoginAndUser(parameter, o, false); } |
230 | 229 | |
231 | - private static object CreateLastUpdatedTrigger(object parameter, object o) { return _RemoveAndCreateLastUpdatedTrigger(parameter, o, false); } | |
232 | - private static object RemoveLastUpdatedTrigger(object parameter, object o) { return _RemoveAndCreateLastUpdatedTrigger(parameter, o, true); } | |
230 | + private static object ManageLastUpdatedTrigger(object parameter, object o) { return _ManageLastUpdatedTrigger(parameter, o, null); } | |
233 | 231 | #region script texts for _RemoveAndCreateLastUpdatedTrigger |
234 | 232 | const string Header_Script = |
235 | 233 | @"USE [{DBNAME}] |
... | ... | @@ -276,37 +274,52 @@ DROP TRIGGER [{SCHEMA}].[{TRIGGER}]; |
276 | 274 | GO |
277 | 275 | "; |
278 | 276 | #endregion script texts for _RemoveAndCreateLastUpdatedTrigger |
279 | - private static object _RemoveAndCreateLastUpdatedTrigger(object parameter, object o,bool removeonly) | |
277 | + /// <summary> | |
278 | + /// Create or remove trigger | |
279 | + /// </summary> | |
280 | + /// <param name="parameter"></param> | |
281 | + /// <param name="o"></param> | |
282 | + /// <param name="forceremoveonly">null=action will be interactively selected; true=action is remove; false=action is recreate</param> | |
283 | + /// <returns></returns> | |
284 | + private static object _ManageLastUpdatedTrigger(object parameter, object o,bool? forceremoveonly) | |
280 | 285 | { |
286 | + var config = (parameter as Menu.ExecutorParameter).GetConfig<SQLDataBaseManagerXmlProcessor>(); | |
287 | + var args = (parameter as Menu.ExecutorParameter).Args; | |
288 | + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); | |
289 | + var menufolders = DisplaySQLDataBaseMenu(config, $"Select the SQL database(s) to manage with function '{nameof(ManageLastUpdatedTrigger)}'!", silent: true); | |
290 | + Menu.Selection sr = menufolders.Select(selectedtaskindexes); | |
291 | + if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
292 | + else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
293 | + else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
294 | + else if (sr.Result == Menu.SelectionResult.Ok) { } | |
295 | + else { } | |
296 | + var p = sr.SelectedParameterList.FirstOrDefault(); | |
297 | + if (p == null) { return o; } | |
298 | + SQLDataBase sqld = p.Parameters as SQLDataBase; | |
299 | + | |
300 | + var manageaction = !forceremoveonly.HasValue; | |
301 | + string actiontext = manageaction ? "MANAGING": (forceremoveonly.Value ? "REMOVING" : "CREATING"); | |
302 | + getparameters:; | |
281 | 303 | try |
282 | 304 | { |
283 | - var config = (parameter as Menu.ExecutorParameter).GetConfig<SQLDataBaseManagerXmlProcessor>(); | |
284 | - var args = (parameter as Menu.ExecutorParameter).Args; | |
285 | - var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); | |
286 | - var menufolders = DisplaySQLDataBaseMenu(config, $"Select the SQL database(s) to manage with function '{nameof(CreateLastUpdatedTrigger)}'!", silent: true); | |
287 | - Menu.Selection sr = menufolders.Select(selectedtaskindexes); | |
288 | - if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
289 | - else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
290 | - else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
291 | - else if (sr.Result == Menu.SelectionResult.Ok) { } | |
292 | - else { } | |
293 | - var p = sr.SelectedParameterList.FirstOrDefault(); | |
294 | - if (p == null) { return o; } | |
295 | - SQLDataBase sqld = p.Parameters as SQLDataBase; | |
305 | + ColorConsole.WriteLine(prefix: $" Enter the parameters for {actiontext} LastUpdated trigger.", bracket: "", text: "", f: ConsoleColor.Yellow); | |
306 | + string formattext = (manageaction?"[-]":"")+ "[DBNAME,][SCHEMA.]TABLE[,COLUMN]"; | |
307 | + ColorConsole.WriteLine(prefix: $" Format:", bracket: "", text: formattext, f: ConsoleColor.Yellow); | |
296 | 308 | |
297 | - getparameters:; | |
298 | - string action = removeonly ? "REMOVING" : "CREATING"; | |
299 | - ColorConsole.WriteLine(prefix: $"Enter the parameters for {action} LastUpdated trigger.", bracket: "", text: "", f: ConsoleColor.Yellow); | |
300 | - ColorConsole.WriteLine(prefix: $" Format#1:", bracket: "()", text: "DBNAME,TABLEWITHSCHEMA,COLUMN", f: ConsoleColor.Yellow); | |
301 | - ColorConsole.WriteLine(prefix: $" Format#2:", bracket: "()", text: "TABLEWITHSCHEMA,COLUMN", f: ConsoleColor.Yellow); | |
302 | - ColorConsole.WriteLine(prefix: $" Format#3:", bracket: "()", text: "TABLEWITHSCHEMA", f: ConsoleColor.Yellow); | |
303 | 309 | ColorConsole.WriteLine(prefix: " ", text: "DBNAME", bracket: "", suffix: $": name of the database of the trigger; default is {sqld.DBName} (example:LearALM2)"); |
304 | - ColorConsole.WriteLine(prefix: " ", text: "[SCHEMA.]TABLE", bracket: "", suffix: $": name of the table (with schema) of the trigger; default dbo (example:ALM.ProductionPeriods)"); | |
310 | + ColorConsole.WriteLine(prefix: " ", text: "TABLE", bracket: "", suffix: $": MANDATORY name of the table of the trigger (example:ProductionPeriods)"); | |
311 | + ColorConsole.WriteLine(prefix: " ", text: "SCHEMA", bracket: "", suffix: $": name of the schema of the table and of the trigger; default dbo (example:ALM)"); | |
305 | 312 | ColorConsole.WriteLine(prefix: " ", text: "COLUMN", bracket: "", suffix: $": name of the column (will be created) of the trigger; default is LastUpdated (example:LastUpdated)"); |
313 | + ColorConsole.WriteLine(prefix: " ", text: "- sign", bracket: "", suffix: $": add minus sign(-) as the first character, to remove the trigger+datafield (example:-LearALM2,ALM.ProductionPeriods,LastUpdated):"); | |
306 | 314 | |
307 | - var createtriggerparameters = ColorConsole.ReadLine($"EX=exit.", ConsoleColor.Yellow, suffix: " --> "); | |
315 | + var createtriggerparameters = ColorConsole.ReadLine($"", ConsoleColor.Yellow, suffix: ""); | |
308 | 316 | if (createtriggerparameters.ToUpper() == "EX") { return o; } |
309 | 317 | if (string.IsNullOrWhiteSpace(createtriggerparameters)) { goto getparameters; } |
318 | + | |
319 | + bool removeactionselected = createtriggerparameters.Substring(1) == "-"; | |
320 | + bool effectiveremoveaction = manageaction && removeactionselected || !manageaction && forceremoveonly.Value; | |
321 | + string effectiveactiontext = effectiveremoveaction ? "REMOVE" : "CREATE"; | |
322 | + createtriggerparameters = createtriggerparameters.Substring(0,1) == "-" ?createtriggerparameters.Substring(1): createtriggerparameters; | |
310 | 323 | var optionList = createtriggerparameters.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); |
311 | 324 | |
312 | 325 | string db = ""; |
... | ... | @@ -326,13 +339,19 @@ GO |
326 | 339 | if (tablewithschemasplitted.Length != 1 && tablewithschemasplitted.Length != 2) { ColorConsole.WriteLine("ERROR! TABLEWITHSCHEMA incorrect!", ConsoleColor.Red); goto getparameters; } |
327 | 340 | if (string.IsNullOrWhiteSpace(column)) { ColorConsole.WriteLine("ERROR! COLUMN can not be empty!", ConsoleColor.Red); goto getparameters; } |
328 | 341 | |
329 | - string schema = ""; | |
342 | + string schema = "dbo"; | |
330 | 343 | string table = tablewithschema; |
331 | 344 | if (tablewithschemasplitted.Length == 2) { schema = tablewithschemasplitted[0]; table = tablewithschemasplitted[1]; } |
332 | 345 | string triggername = $"TRG_LASTUPDATETS_{db}_{schema}_{table}_{column}"; |
333 | 346 | string parameters = $"DBNAME={db};SCHEMA={schema};TABLE={table};COLUMN={column};TRIGGER={triggername};"; |
334 | 347 | string ssScriptText = null; |
335 | 348 | |
349 | + string triggerfulldesignation = $"db={db},table={schema}.{table},column={column},trigger={triggername}"; | |
350 | + ColorConsole.WriteLine(prefix: $"Action to execute:{effectiveactiontext}.", text: $" {triggerfulldesignation}.", bracket: "", suffix: $""); | |
351 | + var confirm = ColorConsole.ReadLine($"Enter CONFIRM to confirm, NO to continue.", ConsoleColor.Yellow, suffix: ""); | |
352 | + if (createtriggerparameters.ToUpper() == "EX") { return o; } | |
353 | + if (confirm.ToUpper() != "CONFIRM") { goto getparameters; } | |
354 | + | |
336 | 355 | if (!Tools.ResolveArguments(parameters, RemoveLastUpdatedTrigger_Script, out ssScriptText)) { throw new ApplicationException(); } |
337 | 356 | try {SQLDataBaseManagerCore.ExecuteSQLScript(sqld.SQLCS, ssScriptText, 5000, null); } |
338 | 357 | catch (Exception e) {ColorConsole.WriteLine(e.Message, ConsoleColor.Yellow);} |
... | ... | @@ -340,7 +359,7 @@ GO |
340 | 359 | try {SQLDataBaseManagerCore.ExecuteSQLScript(sqld.SQLCS, ssScriptText, 5000, null);} |
341 | 360 | catch (Exception e) { ColorConsole.WriteLine(e.Message, ConsoleColor.Yellow); } |
342 | 361 | |
343 | - if (!removeonly) | |
362 | + if (!effectiveremoveaction) | |
344 | 363 | { |
345 | 364 | if (!Tools.ResolveArguments(parameters, CreateLastUpdatedColumn_Script, out ssScriptText)) { throw new ApplicationException(); } |
346 | 365 | SQLDataBaseManagerCore.ExecuteSQLScript(sqld.SQLCS, ssScriptText, 5000, null); |
... | ... | @@ -351,18 +370,18 @@ GO |
351 | 370 | if (!Tools.ResolveArguments(parameters, EnableLastUpdatedTrigger_Script, out ssScriptText)) { throw new ApplicationException(); } |
352 | 371 | SQLDataBaseManagerCore.ExecuteSQLScript(sqld.SQLCS, ssScriptText, 5000, null); |
353 | 372 | } |
354 | - ColorConsole.WriteLine($"SUCCESS! {action} trigger to store LastUpdate TimeStamp: Database={db},Table={schema}.{table},Column={column}", ConsoleColor.Green); | |
355 | - return o; | |
373 | + ColorConsole.WriteLine($"SUCCESS! {effectiveactiontext} trigger to store LastUpdate TimeStamp: {triggerfulldesignation}", ConsoleColor.Green); | |
374 | + goto getparameters; | |
356 | 375 | } |
357 | 376 | catch (ApplicationException e) |
358 | 377 | { |
359 | - ColorConsole.WriteLine("FATAL ERROR! in script parameter substitution!", ConsoleColor.Red); | |
360 | - return o; | |
378 | + ColorConsole.WriteLine("FATAL ERROR! in script parameter substitution!", ConsoleColor.Red); | |
379 | + goto getparameters; | |
361 | 380 | } |
362 | 381 | catch (Exception e) |
363 | 382 | { |
364 | - ColorConsole.WriteLine("FATAL ERROR! "+e.Message, ConsoleColor.Red); | |
365 | - return o; | |
383 | + ColorConsole.WriteLine("FATAL ERROR! "+e.Message, ConsoleColor.Red); | |
384 | + goto getparameters; | |
366 | 385 | } |
367 | 386 | } |
368 | 387 | private static object _CreteLoginAndUser(object parameter, object o,bool createlogin) | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
... | ... | @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; |
32 | 32 | // You can specify all the values or you can default the Build and Revision Numbers |
33 | 33 | // by using the '*' as shown below: |
34 | 34 | // [assembly: AssemblyVersion("1.0.*")] |
35 | -[assembly: AssemblyVersion("1.25.0.0")] | |
36 | -[assembly: AssemblyFileVersion("1.25.0.0")] | |
35 | +[assembly: AssemblyVersion("1.25.1.0")] | |
36 | +[assembly: AssemblyFileVersion("1.25.1.0")] | ... | ... |