static void LogMessage(string Message, string Type, string Caller) { #if DEBUG Console.WriteLine("Log : Caller was : {0}; Type: {1}; Message: {2} ;", Caller, Type, Message); #endif if (string.IsNullOrWhiteSpace(Type)) { Type = "Unknown"; } if (Type == "Debug" && GlobalStatic.DebugMode == false) { return; } if (Type == "PopUp") { GraphicsWindow.ShowMessage(Message, Caller); } else if (Message.Contains("LDDataBase.Query") == true || Message.Contains("LDDataBase.Command") == true) { if (Message.Contains("logic error")) { Type = "SQL Error"; GraphicsWindow.ShowMessage(Message, Type); } } else if (Message.Contains("Shape not found")) { Type = "Shape"; } int StackPointer = Stack.Add($"Events.LogMessage({Message},{Type},{Caller})"); string LogCMD = "INSERT INTO LOG ([UTC DATE],[UTC TIME],DATE,TIME,USER,ProductID,ProductVersion,Event,Type) VALUES(DATE(),TIME(),DATE('now','localtime'),TIME('now','localtime'),'" + GlobalStatic.UserName + "','" + GlobalStatic.ProductID + "','" + GlobalStatic.VersionID + "','" + Message.Replace("\n", "") + "','" + Type + "');";; var CS = new Engines.CommandSettings() { Database = GlobalStatic.LogDB, SQL = LogCMD, User = Language.Localization["App"], Explanation = Language.Localization["Auto Log"] }; Engines.Command(CS); Stack.Exit(StackPointer); }
/// <summary> /// Connects to and creates Log and Transaction databases with default tables. /// </summary> public static void IniateDatabases() { int StackPointer = Stack.Add("Settings.IniateDatabases()"); if (string.IsNullOrWhiteSpace(GlobalStatic.TransactionDBPath) || string.IsNullOrWhiteSpace(GlobalStatic.LogDBpath)) { throw new ArgumentNullException("Transaction or Log Path is null"); } GlobalStatic.TransactionDB = Engines.Load.Sqlite(GlobalStatic.TransactionDBPath, "Transaction Log"); GlobalStatic.LogDB = Engines.Load.Sqlite(GlobalStatic.LogDBpath, "Master Log"); var LogCS = new Engines.CommandSettings() { Database = GlobalStatic.LogDB, SQL = GlobalStatic.LOGSQL, User = GlobalStatic.UserName, Explanation = "Auto Creation Statements" }; var LogView = new Engines.CommandSettings() { Database = GlobalStatic.LogDB, SQL = GlobalStatic.LOGSQLVIEW, User = GlobalStatic.UserName, Explanation = "Auto Creation Statements" }; var Transactions = new Engines.CommandSettings() { Database = GlobalStatic.TransactionDB, SQL = GlobalStatic.TransactionsSQL, User = GlobalStatic.UserName, Explanation = "Auto Creation Statements" }; Engines.Command(LogCS); Engines.Command(LogView); Engines.Command(Transactions); Stack.Exit(StackPointer); }
public static void CreateTableHandler() { int StackPointer = Stack.Add("UI.CreateTableHandler()"); string LastButton = Controls.LastClickedButton; string Name = Controls.GetTextBoxText(_TextBox["Table_Name"]); if (LastButton == _Buttons["Commit"]) { if (!string.IsNullOrWhiteSpace(Name)) { Name = Name.Replace("[", "").Replace("]", "").Replace("\"", ""); int Max = LDControls.DataViewRowCount(GlobalStatic.Dataview); StringBuilder Define_SQL = new StringBuilder(); Define_SQL.Append("CREATE TABLE \"" + Name + "\"("); for (int i = 1; i <= Max; i++) { Primitive _Data = LDControls.DataViewGetRow(GlobalStatic.Dataview, i); if (!string.IsNullOrWhiteSpace(_Data[1])) { if (_Data[4] == true) { _Data[3] = true; } string Field = ((string)_Data[1]).Replace("[", "").Replace("]", "").Replace("\"", ""); Define_SQL.AppendFormat("\"{0}\" {1}", Field, (string)_Data[2]); if (_Data[6] == true) { Define_SQL.Append(" NOT NULL"); } if (_Data[3] == true) { Define_SQL.Append(" PRIMARY KEY"); } if (_Data[4] == true) { Define_SQL.Append(" AUTOINCREMENT"); } if (_Data[5] == true) { Define_SQL.Append(" UNIQUE"); } if (i != Max) { Define_SQL.Append(","); } else { Define_SQL.Append(");"); } } } if (!string.IsNullOrWhiteSpace(Engines.CurrentDatabase)) { string Confirmation = LDDialogs.Confirm("Do you wish to commit the following SQL:\n" + Define_SQL.ToString() + "\n to " + Engines.DB_ShortName[Engines.DB_Name.IndexOf(Engines.CurrentDatabase)], "Commit SQL"); if (Confirmation == "Yes") { Engines.CommandSettings CS = new Engines.CommandSettings() { Database = Engines.CurrentDatabase, SQL = Define_SQL.ToString(), User = GlobalStatic.UserName, Explanation = "User Defining a Table" //Localize }; Engines.Command(CS); } } } else { GraphicsWindow.ShowMessage("Table Name is not empty, please fill it!", "NAME"); } Stack.Exit(StackPointer); return; } if (LastButton == _Buttons["Exit"]) { Controls.ButtonClicked -= CreateTableHandler; Controls.ButtonClicked += Events.BC; ClearWindow(); DisplayResults(); ShowDisplayResults(); MainMenu(); //Events.MC("View"); Stack.Exit(StackPointer); return; } Stack.Exit(StackPointer); }
public static void Buttons(string LastButton) { int StackPointer = Stack.Add($"Handlers.Buttons({LastButton})"); try { if (LastButton == UI.Buttons["Search"] || LastButton == UI.Buttons["Sort"] || LastButton == UI.Buttons["RunFunction"]) { Primitive ASCDESC_Sorts = "1=ASC;2=DESC;3=RANDOM();"; bool Search = false, Sort = true, Function = false; bool.TryParse(LDControls.CheckBoxGetState(GlobalStatic.CheckBox["StrictSearch"]), out bool StrictSearch); bool.TryParse(LDControls.CheckBoxGetState(GlobalStatic.CheckBox["InvertSearch"]), out bool InvertSearch); string SearchIn = "\"" + Engines.Schema[LDControls.ComboBoxGetSelected(GlobalStatic.ComboBox["Search"])] + "\""; string SearchText = Controls.GetTextBoxText(UI.TextBox["Search"]).ToString().Replace("'", "''"); string FunctionIn = "\"" + Engines.Schema[LDControls.ComboBoxGetSelected(GlobalStatic.ComboBox["ColumnList"])] + "\""; string FunctionCalled = Engines.Functions(Engines.CurrentEngine)[LDControls.ComboBoxGetSelected(GlobalStatic.ComboBox["FunctionList"]) - 1]; string SortBy = "\"" + Engines.Schema[LDControls.ComboBoxGetSelected(GlobalStatic.ComboBox["Sort"])] + "\""; string ASCDESC = ASCDESC_Sorts[LDControls.ComboBoxGetSelected(GlobalStatic.ComboBox["ASCDESC"])]; if (LastButton == UI.Buttons["Search"]) { Search = true; } else if (LastButton == UI.Buttons["RunFunction"]) { Function = true; } /* * Console.WriteLine(); * Console.WriteLine("Search: {0} Sort : {1} Function :{2}", Search, Sort, Function); * Console.WriteLine("Strict Search : {0} Invert Search : {1}", StrictSearch, InvertSearch); * Console.WriteLine("SearchIn : {0} Search Text : {1} FunctionIn : {2} FunctionCalled : {3} SortBy : {4} ASCDESC : {5} LastButton : {6}", SearchIn, SearchText, FunctionIn, FunctionCalled, SortBy, ASCDESC, Controls.GetButtonCaption(LastButton)); */ var GQS = new Engines.GenerateQuerySettings { //bool Search = Search, Sort = Sort, RunFunction = Function, SearchBy = SearchIn, OrderBy = SortBy, StrictSearch = StrictSearch, InvertSearch = InvertSearch, FunctionSelected = FunctionCalled, FunctionColumn = FunctionIn, SearchText = SearchText }; switch (ASCDESC) { case "ASC": GQS.Order = Engines.GenerateQuerySettings.SortOrder.Ascending; break; case "DESC": GQS.Order = Engines.GenerateQuerySettings.SortOrder.Descding; break; case "RANDOM()": GQS.Order = Engines.GenerateQuerySettings.SortOrder.Random; break; } string Query = Engines.GenerateQuery(GQS, Engines.CurrentTable.SanitizeFieldName()); Engines.QuerySettings QS = new Engines.QuerySettings { Database = Engines.CurrentDatabase, SQL = Query, ListView = GlobalStatic.ListView, User = GlobalStatic.UserName, Explanation = "Auto Generated Query on behalf of " + GlobalStatic.UserName }; Engines.Query(QS); } else if (LastButton == UI.Buttons["Query"]) { Engines.Cache.Clear(); Engines.QuerySettings QS = new Engines.QuerySettings { Database = Engines.CurrentDatabase, SQL = Controls.GetTextBoxText(UI.TextBox["CustomQuery"]), ListView = GlobalStatic.ListView, User = GlobalStatic.UserName, Explanation = Language.Localization["User Requested"] }; Engines.Query(QS); } else if (LastButton == UI.Buttons["Command"]) //Custom Command { Engines.Cache.Clear(); var CS = new Engines.CommandSettings() { Database = Engines.CurrentDatabase, SQL = Controls.GetTextBoxText(UI.TextBox["CustomQuery"]), User = GlobalStatic.UserName, Explanation = Language.Localization["User Requested"] }; Engines.Command(CS); } } catch (KeyNotFoundException) { string Message = Controls.GetButtonCaption(LastButton) + "(" + LastButton + ") |" + UI.Buttons.ContainsKey(LastButton) + "|" + Controls.GetButtonCaption(LastButton) == Language.Localization["Query"].ToUpper() + "| does not exist in context or has not yet implemented."; Events.LogMessage(Message, "System"); } Stack.Exit(StackPointer); }