static void Database(int Index) { Tracker.Add(Engines.DB_ShortName[Index - 1]); Engines.Load.Sqlite(Engines.DB_Path[Index - 1]); Engines.GetSchema(Engines.CurrentDatabase); Engines.GetColumnsofTable(Engines.CurrentDatabase, Engines.CurrentTable); LDControls.ComboBoxContent(GlobalStatic.ComboBox["FunctionList"], Engines.Functions(Engines.EnginesMode.SQLITE).ToPrimitiveArray()); Sorts(1); Table(1); LDControls.ComboBoxSelect(GlobalStatic.ComboBox["Sorts"], 1); LDControls.ComboBoxSelect(GlobalStatic.ComboBox["Table"], 1); if (GlobalStatic.SortBy == 4) { Engines.SetDefaultTable("sqlite_master"); Engines.GetColumnsofTable(Engines.CurrentDatabase, Engines.CurrentTable); LDControls.ComboBoxContent(GlobalStatic.ComboBox["Table"], "1=" + Engines.CurrentTable + ";2=sqlite_temp_master;"); return; } Engines.GetColumnsofTable(Engines.CurrentDatabase, Engines.CurrentTable); return; }
static void Table(int Index) { //Prevents OutofBound Exceptions if (CorrectList.Count >= Index) { Engines.SetDefaultTable(CorrectList[Index - 1]); Engines.GetColumnsofTable(Engines.CurrentDatabase, Engines.CurrentTable); Bind(); } }
public static Primitive Generate2DArray(string Database, string SQL) { Engines.QuerySettings QS = new Engines.QuerySettings { Database = Database, SQL = SQL, FetchRecords = true, User = GlobalStatic.UserName }; return(Engines.Query(QS)); }
public static void MainMenu() { int StackReference = Stack.Add("UI.MainMenu()"); LDGraphicsWindow.ExitButtonMode(GraphicsWindow.Title, "Enabled"); GraphicsWindow.CanResize = true; LDGraphicsWindow.State = 2; GraphicsWindow.Title = GlobalStatic.Title + " "; Primitive Sorts = $"1={Language.Localization["Table"]};2={Language.Localization["View"]};3={Language.Localization["Index"]};4={Language.Localization["Master Table"]};"; if (Engines.CurrentDatabase != null && Engines.CurrentDatabase != null) { Engines.GetSchema(Engines.CurrentDatabase); } GraphicsWindow.FontSize = GlobalStatic.DefaultFontSize + 8; int UIx = GlobalStatic.Listview_Width - 380; string Menu = LDControls.AddMenu(Desktop.Width * 1.5, 30, MenuList, IconList, null); Shapes.Move(Shapes.AddText(Language.Localization["Sort"] + ":"), UIx, 1); int TextWidth = LDText.GetHeight(Language.Localization["Sort"] + ":"); GraphicsWindow.FontSize = GlobalStatic.DefaultFontSize; try { GlobalStatic.ComboBox["Table"] = LDControls.AddComboBox(Engines.Tables.ToPrimitiveArray(), 100, 100); } catch (Exception ex) { Events.LogMessage(ex.ToString(), "System"); } GlobalStatic.ComboBox["Sorts"] = LDControls.AddComboBox(Sorts, 100, 100); GlobalStatic.ComboBox["Database"] = LDControls.AddComboBox(Engines.DB_ShortName.ToPrimitiveArray(), 100, 100); Controls.Move(GlobalStatic.ComboBox["Database"], UIx + TextWidth + 35, 5); Controls.Move(GlobalStatic.ComboBox["Sorts"], UIx + TextWidth + 150, 5); Controls.Move(GlobalStatic.ComboBox["Table"], UIx + TextWidth + 260, 5); //Virtual Call to Handler Events.MC(Language.Localization["View"]); Title(); Controls.ButtonClicked += Events.BC; LDControls.MenuClicked += Events.MC; LDControls.ComboBoxItemChanged += Events.CB; LDControls.ContextMenuClicked += Events.MI; Stack.Exit(StackReference); }
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); }
public static void Startup() { int StackPointer = Stack.Add("UI.Startup()"); try { DBM.Settings.Load(GlobalStatic.RestoreSettings, GlobalStatic.SettingsPath); DBM.Settings.Paths ( GlobalStatic.AssetPath, GlobalStatic.PluginPath, GlobalStatic.LocalizationFolder, GlobalStatic.AutoRunPluginPath, GlobalStatic.Localization_LanguageCodes_Path, GlobalStatic.AutoRunPluginMessage ); //Makes sure passed paths are valid and creates them if they are not } catch (Exception) { } DBM.Settings.IniateDatabases(); Engines.CreateBindList(); Language.Load( Path.Combine(GlobalStatic.LocalizationFolder, GlobalStatic.LanguageCode + ".xml"), Path.Combine(GlobalStatic.Localization_LanguageCodes_Path, GlobalStatic.LanguageCode + ".txt") ); Events.LogMessage(Language.Localization["PRGM Start"], Language.Localization["Application"]); if (Program.ArgumentCount == 1) { Engines.Load.Sqlite(GetPath(Engines.EnginesMode.SQLITE)); } if (RunProgram) { StartupGUI(); } else { DBM.Settings.Save(); EULA.UI(GlobalStatic.EULA_Text_File, 0, GlobalStatic.Title, GlobalStatic.Copyright, GlobalStatic.ProductID); } StartUpStopWatch.Stop(); Events.LogMessage($"Startup Time : {StartUpStopWatch.ElapsedMilliseconds} (ms).", Language.Localization["UI"]); Stack.Exit(StackPointer); }
static void GenerateChart(List <string> Columns, Dictionary <string, string> Types, Primitive QueryData) { //Process Columns for (int i = 0; i < Columns.Count; i++) { try { switch (Types[Columns[i]]) { case "Number": chart.AddColumn(Columns[i], Google_Charts.Chart.DataType.number); break; case "Text": default: chart.AddColumn(Columns[i]); break; } } catch (KeyNotFoundException) {} } Primitive Indices = QueryData[1].GetAllIndices(); //Tranforms Data for (int i = 1; i <= QueryData.GetItemCount(); i++) { for (int ii = 1; ii <= QueryData[i].GetItemCount(); ii++) { if (Columns.Contains(Indices[ii])) { chart.AddRowData(i - 1, QueryData[i][Indices[ii]]); } } } chart.Title = Controls.GetTextBoxText(TitleTB); chart.SubTitle = Controls.GetTextBoxText(SubTitleTB); chart.Xaxis = Controls.GetTextBoxText(XaxisCaptionTB); chart.Yaxis = Controls.GetTextBoxText(YaxisCaptionTB); string OutPut = Path.GetDirectoryName(Engines.DB_Path[Engines.GetDataBaseIndex(Engines.CurrentDatabase)]) + string.Format("\\{0} {1} Chart.html", Engines.CurrentTable.SanitizeFieldName(), chart.ChartType); chart.Write(OutPut); LDProcess.Start(OutPut, null); }
/// <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); }
static void Sorts(int Index) { GlobalStatic.SortBy = Index; //Sets GlobalStatic.SortBy. Count by 1 instead of zero if (Schema.ContainsKey(Index)) { CorrectList = Schema[Index]; if (CorrectList.Count > 0) { Engines.SetDefaultTable(CorrectList[0]); LDControls.ComboBoxContent(GlobalStatic.ComboBox["Table"], CorrectList.ToPrimitiveArray()); Engines.GetColumnsofTable(Engines.CurrentDatabase, Engines.CurrentTable); } } if (!string.IsNullOrWhiteSpace(Engines.CurrentTable)) { UI.HideDisplayResults(); Bind(); UI.Title(); return; } Events.LogMessage("In the current database no " + Language.Localization[TypeofSorts[GlobalStatic.SortBy]] + "s can be found.", Language.Localization["UI"]); }
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 DisplayResults() { int StackPointer = Stack.Add("UI.DisplayResults()"); LDGraphicsWindow.PauseUpdates(); //Clears the Dictionary to prevent errors _Buttons.Clear(); _TextBox.Clear(); /* * _CheckBox.Clear(); * _ComboBox.Clear(); */ LDGraphicsWindow.Width = Desktop.Width; LDGraphicsWindow.Height = Desktop.Height; GraphicsWindow.Left = 0; GraphicsWindow.Top = 0; GlobalStatic.UIx = GlobalStatic.Listview_Width + 50; DisplayHelper(); //Sort GraphicsWindow.FontSize = GlobalStatic.DefaultFontSize + 1; string AscDesc = "1=" + Language.Localization["Asc"] + ";2=" + Language.Localization["Desc"] + ";3=RANDOM();"; GlobalStatic.ComboBox["Sort"] = LDControls.AddComboBox(Engines.Schema, 100, 100); GlobalStatic.ComboBox["ASCDESC"] = LDControls.AddComboBox(AscDesc, 110, 100); _Buttons.AddOrReplace("Sort", Controls.AddButton(Language.Localization["Sort"], GlobalStatic.UIx + 10, 120)); Controls.Move(GlobalStatic.ComboBox["Sort"], GlobalStatic.UIx + 80, 77); Controls.Move(GlobalStatic.ComboBox["ASCDESC"], GlobalStatic.UIx + 190, 77); Controls.SetSize(_Buttons["Sort"], 290, 30); LDDialogs.ToolTip(_Buttons["Sort"], "Iniates a sort based on user set parameters"); //Localize LDDialogs.ToolTip(GlobalStatic.ComboBox["ASCDESC"], "Sorts Ascending and Decending based on position"); //Localize //Search GlobalStatic.ComboBox["Search"] = LDControls.AddComboBox(Engines.Schema, 200, 120); _TextBox.AddOrReplace("Search", Controls.AddTextBox(GlobalStatic.UIx + 100, 210)); GlobalStatic.CheckBox["StrictSearch"] = LDControls.AddCheckBox(Language.Localization["Strict Search"]); GlobalStatic.CheckBox["InvertSearch"] = LDControls.AddCheckBox(Language.Localization["Invert"]); _Buttons.AddOrReplace("Search", Controls.AddButton(Language.Localization["Search"].ToUpper(), GlobalStatic.UIx + 10, 260)); Controls.Move(GlobalStatic.CheckBox["StrictSearch"], GlobalStatic.UIx + 20, 240); Controls.Move(GlobalStatic.CheckBox["InvertSearch"], GlobalStatic.UIx + 150, 240); Controls.Move(GlobalStatic.ComboBox["Search"], GlobalStatic.UIx + 100, 180); Controls.SetSize(_TextBox["Search"], 200, 25); Controls.SetSize(_Buttons["Search"], 290, 30); //Functions GlobalStatic.ComboBox["FunctionList"] = LDControls.AddComboBox(Engines.Functions(Engines.CurrentEngine).ToPrimitiveArray(), 130, 100); GlobalStatic.ComboBox["ColumnList"] = LDControls.AddComboBox(Engines.Schema, 135, 100); Controls.Move(GlobalStatic.ComboBox["FunctionList"], GlobalStatic.UIx + 10, 315); Controls.Move(GlobalStatic.ComboBox["ColumnList"], GlobalStatic.UIx + 160, 315); _Buttons.AddOrReplace("RunFunction", Controls.AddButton(Language.Localization["Run Function"].ToUpper(), GlobalStatic.UIx + 10, 345)); Controls.SetSize(_Buttons["RunFunction"], 290, 30); //Custom Query _TextBox["CustomQuery"] = Controls.AddMultiLineTextBox(GlobalStatic.UIx, 420); Controls.SetSize(_TextBox["CustomQuery"], 310, 150); _Buttons.AddOrReplace("Query", Controls.AddButton(Language.Localization["Query"].ToUpper(), GlobalStatic.UIx, 580)); Controls.SetSize(_Buttons["Query"], 310, 30); _Buttons.AddOrReplace("Command", Controls.AddButton(Language.Localization["Command"].ToUpper(), GlobalStatic.UIx, 615)); Controls.SetSize(_Buttons["Command"], 310, 30); LDDialogs.ToolTip(_Buttons["Command"], "Executes customized SQL command statements onto the database"); //Localize string CustomQueryData = "This Textbox allows you to use Custom\nSQL Queries. Remove this and type in an SQL \nstatement. \nYou also use it to export data"; //Localize Controls.SetTextBoxText(_TextBox["CustomQuery"], CustomQueryData); //Hide Display Results _HideDisplay.Clear(); _HideDisplay.Add(GlobalStatic.ComboBox["Sort"]); _HideDisplay.Add(GlobalStatic.ComboBox["ASCDESC"]); _HideDisplay.Add(Buttons["Sort"]); _HideDisplay.Add(GlobalStatic.ComboBox["Search"]); _HideDisplay.Add(_TextBox["Search"]); _HideDisplay.Add(GlobalStatic.CheckBox["StrictSearch"]); _HideDisplay.Add(GlobalStatic.CheckBox["InvertSearch"]); _HideDisplay.Add(Buttons["Search"]); _HideDisplay.Add(GlobalStatic.ComboBox["FunctionList"]); _HideDisplay.Add(GlobalStatic.ComboBox["ColumnList"]); _HideDisplay.Add(Buttons["RunFunction"]); _HideDisplay.Add(_TextBox["CustomQuery"]); _HideDisplay.Add(Buttons["Query"]); _HideDisplay.Add(Buttons["Command"]); LDGraphicsWindow.ResumeUpdates(); Stack.Exit(StackPointer); }
static void Handler() { string LastListBox = LDControls.LastListBox; string LCB = Controls.LastClickedButton; int Node = LDControls.ListBoxGetSelected(LastListBox) - 1; List <string> CurrentList = null; string Item = null; if (LastListBox == SchemaListBox) { CurrentList = Schema; } else if (LastListBox == XListBox) { CurrentList = XColumns; } else if (LastListBox == YListBox) { CurrentList = YColumns; } if (Node >= 0) { Item = CurrentList[Node]; } if (LCB == GenerateChartButton) { List <string> Columns = new List <string>(); Columns.AddRange(XColumns); Columns.AddRange(YColumns); Dictionary <string, string> Types = new Dictionary <string, string>(); for (int i = 1; i <= LDControls.DataViewRowCount(DataView); i++) { Types.Add(LDControls.DataViewGetValue(DataView, i, 1), LDControls.DataViewGetValue(DataView, i, 2)); } Engines.QuerySettings QS = new Engines.QuerySettings { Database = Engines.CurrentDatabase, SQL = Engines.NonSchemaQuery.Last(), FetchRecords = true, User = GlobalStatic.UserName, Explanation = "Generating Chart" //TODO Localize }; GenerateChart(Columns, Types, Engines.Query(QS)); Clear(); GraphicsWindow.ShowMessage("Exported Chart!", "Success"); } else if (LCB == Escape) { Clear(); } else if (CurrentList?.Count >= Node) { try { if (LCB == Left1) { Schema.RemoveAt(Node); XColumns.Add(Item); } else if (LCB == Right1) { XColumns.RemoveAt(Node); Schema.Add(Item); } else if (LCB == Left2) { YColumns.RemoveAt(Node); Schema.Add(Item); } else if (LCB == Right2) { Schema.RemoveAt(Node); YColumns.Add(Item); } } catch (ArgumentOutOfRangeException ex) { Events.LogMessage(ex.Message, Language.Localization["System"]); } } if (LCB != Escape) { Binder(); AutoHide(); } }
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); }
/// <summary> /// Handles Main Menu /// </summary> /// <param name="Item">Localized Menu Item</param> public static void Menu(string Item) { int StackPointer = Stack.Add($"Handlers.Menu({Item})"); //Switch and Enum cannot be used because values can change //File Menu Items if (Item == Language.Localization["New"]) { string Path = LDDialogs.SaveFile(GlobalStatic.Extensions, GlobalStatic.LastFolder); if (!string.IsNullOrWhiteSpace(Path)) { GlobalStatic.ListView = null; GlobalStatic.Dataview = null; GlobalStatic.LastFolder = System.IO.Path.GetDirectoryName(Path); Settings.Load(GlobalStatic.RestoreSettings, GlobalStatic.SettingsPath); Settings.Save(); LDDataBase.ConnectSQLite(Path); Engines.Load.Sqlite(Path); Events.LogMessage("Created DB :" + Path, Language.Localization["Application"]); UI.PreMainMenu(); UI.MainMenu(); LDDataBase.Connection = null; } Stack.Exit(StackPointer); return; } else if (Item == Language.Localization["Open"]) { GlobalStatic.ListView = null; GlobalStatic.Dataview = null; Settings.Load(GlobalStatic.RestoreSettings, GlobalStatic.SettingsPath); //Reloads Settings string Path = UI.GetPath(Engines.EnginesMode.SQLITE); if (!string.IsNullOrWhiteSpace(Path)) { Engines.Load.Sqlite(Path); GlobalStatic.Settings["LastFolder"] = System.IO.Path.GetDirectoryName(Path); Settings.Save(); UI.PreMainMenu(); UI.MainMenu(); int Index = Engines.DB_Name.IndexOf(Engines.CurrentDatabase) + 1; Handlers.ComboBox.CB(GlobalStatic.ComboBox["Database"], Index); LDControls.ComboBoxSelect(GlobalStatic.ComboBox["Database"], Index); } Stack.Exit(StackPointer); return; } else if (Item == Language.Localization["Define New Table"]) { Engines.Cache.Clear(); UI.CreateTableUI(); } else if (Item == Language.Localization["New in Memory Db"]) { Engines.Load.MemoryDB(Engines.EnginesMode.SQLITE); UI.PreMainMenu(); UI.MainMenu(); } else if (Item == Language.Localization["Create Statistics Page"]) { string Name = string.Format("\"Statistics of {0}\"", Engines.CurrentTable.SanitizeFieldName()); Engines.Transform.CreateStatisticsTable(Engines.CurrentDatabase, Engines.CurrentTable, Name, Export.GenerateSchemaFromLastQuery()); Engines.QuerySettings QS = new Engines.QuerySettings { Database = Engines.CurrentDatabase, SQL = $"SELECT * FROM {Name};", ListView = GlobalStatic.ListView, User = GlobalStatic.UserName, Explanation = Language.Localization["Statistics Page"] }; Engines.Query(QS); Engines.GetSchema(Engines.CurrentDatabase); Engines.SetDefaultTable(Name.SanitizeFieldName()); Engines.GetColumnsofTable(Engines.CurrentDatabase, Name); ComboBox.Bind(); } //Main else if (Item == Language.Localization["View"] || Item == Language.Localization["View"] + " ") { Controls.HideControl(GlobalStatic.Dataview); GlobalStatic.Dataview = null; if (GlobalStatic.ListView == null) { bool Bold = GraphicsWindow.FontBold; GraphicsWindow.FontBold = false; GlobalStatic.ListView = LDControls.AddListView(GlobalStatic.Listview_Width, GlobalStatic.Listview_Height, null); LDControls.AddContextMenu(GlobalStatic.ListView, "1=Ascend;2=Descend;3=Random();", null); Controls.Move(GlobalStatic.ListView, 10, 35); UI.DisplayResults(); GraphicsWindow.FontBold = Bold; } else { UI.ShowDisplayResults(); Controls.ShowControl(GlobalStatic.ListView); } if (!string.IsNullOrEmpty(Engines.CurrentTable)) { Engines.QuerySettings QS = new Engines.QuerySettings { Database = Engines.CurrentDatabase, SQL = $"SELECT * FROM {Engines.CurrentTable};", ListView = GlobalStatic.ListView, User = Language.Localization["App"], Explanation = Language.Localization["View Function"] }; Engines.Query(QS); } Stack.Exit(StackPointer); return; } else if (Item == Language.Localization["Save"]) { if (!string.IsNullOrEmpty(Engines.CurrentDatabase) && !string.IsNullOrEmpty(GlobalStatic.Dataview)) { string SaveStatus = LDDataBase.SaveTable(Engines.CurrentDatabase, GlobalStatic.Dataview); Events.LogMessagePopUp("The save was : " + SaveStatus, Language.Localization["UI"], "Save Status"); } else { Events.LogMessagePopUp(Language.Localization["Dataview Error"], Language.Localization["UI"], "Save Error"); } Stack.Exit(StackPointer); return; } else if (Item == Language.Localization["Edit"]) { if (!string.IsNullOrEmpty(Engines.CurrentDatabase)) { switch (GlobalStatic.SortBy) { case 2: Events.LogMessagePopUp(Language.Localization["Views Read Only"], Language.Localization["UI"], Language.Localization["Access Denied"]); break; case 4: Events.LogMessagePopUp(Language.Localization["Master Table Protected"], Language.Localization["UI"], Language.Localization["Access Denied"]); break; default: Controls.HideControl(GlobalStatic.ListView); if (String.IsNullOrEmpty(GlobalStatic.Dataview)) { GlobalStatic.Dataview = LDControls.AddDataView(GlobalStatic.Listview_Width, GlobalStatic.Listview_Height, null); Controls.Move(GlobalStatic.Dataview, 10, 35); } else { Controls.ShowControl(GlobalStatic.Dataview); } UI.HideDisplayResults(); Engines.EditTable(Engines.CurrentTable, GlobalStatic.Dataview); break; } } else { Events.LogMessagePopUp(Language.Localization["Error No DB"], Language.Localization["UI"], Language.Localization["Edit"]); } Stack.Exit(StackPointer); return; } //Import else if (Item == Language.Localization["CSV"]) { string Path = LDDialogs.OpenFile("csv", null); if (!string.IsNullOrWhiteSpace(Path)) { //Outputted to a temporary path in the event the import doesn't work... string TempPath = System.IO.Path.GetTempFileName().Replace(".tmp", ".sql"); Stopwatch CSV = new Stopwatch(); CSV.Start(); Import.CSV(Path, TempPath); CSV.Stop(); Stopwatch SQL = new Stopwatch(); SQL.Start(); Import.SQL(Engines.CurrentDatabase, TempPath); SQL.Stop(); string ToolTip = string.Format("CSV Import Completed!\n CSV:{0}(ms)\nSQL:{1}(ms)", CSV.ElapsedMilliseconds, SQL.ElapsedMilliseconds); Events.LogMessagePopUp(ToolTip, Language.Localization["UI"], Language.Localization["Importer"]); //TODO Localize Stack.Exit(StackPointer); return; } Events.LogMessagePopUp(Language.Localization["Error Generic"], Language.Localization["UI"], "Import.CSV");//TODO Localize Stack.Exit(StackPointer); return; } else if (Item == Language.Localization["SQL"]) { string Path = LDDialogs.OpenFile("sql", null); if (!string.IsNullOrWhiteSpace(Path)) { Stopwatch SQL = new Stopwatch(); SQL.Start(); Import.SQL(Engines.CurrentDatabase, Path); SQL.Stop(); Events.LogMessagePopUp("SQL Import Completed in " + SQL.ElapsedMilliseconds + "(ms)", Language.Localization["UI"], Language.Localization["Importer"]); //TODO Localize Stack.Exit(StackPointer); return; } Events.LogMessagePopUp(Language.Localization["Error Generic"], Language.Localization["UI"], "Import.SQL");//TODO Localize Stack.Exit(StackPointer); return; } //Export else if (Item == Language.Localization["PXML"] + " ") { string Path = LDDialogs.SaveFile("xml", null); if (!string.IsNullOrWhiteSpace(Path)) { Primitive Data = Export.Generate2DArrayFromLastQuery(); Export.XML(Data, Export.GenerateSchemaFromQueryData(Data), Engines.CurrentTable, Path); Events.LogMessagePopUp("XML export of " + Engines.CurrentTable + " completed!", "Export", "Success"); Stack.Exit(StackPointer); return; } Events.LogMessagePopUp(Language.Localization["Error Generic"], Language.Localization["UI"], "Export.XML");//TODO Localize Stack.Exit(StackPointer); return; } else if (Item == Language.Localization["HTML"] + " ") { string Path = LDDialogs.SaveFile("html", null); if (!string.IsNullOrWhiteSpace(Path)) { Primitive Data = Export.Generate2DArrayFromLastQuery(); Export.HTML(Data, Export.GenerateSchemaFromQueryData(Data), Engines.CurrentTable.SanitizeFieldName(), Path, GlobalStatic.ProductID + " V" + GlobalStatic.VersionID); Events.LogMessagePopUp("HTML export of " + Engines.CurrentTable + " completed!", Language.Localization["Export"], Language.Localization["Success"]); Stack.Exit(StackPointer); return; } Events.LogMessagePopUp(Language.Localization["Error Generic"], Language.Localization["UI"], "Export.HTML");//TODO Localize Stack.Exit(StackPointer); return; } else if (Item == Language.Localization["SQL"] + " ") { string Path = LDDialogs.SaveFile("sql", null); if (!string.IsNullOrWhiteSpace(Path)) { Primitive Data = Export.Generate2DArrayFromLastQuery(); Primitive Schema = Export.GenerateSchemaFromQueryData(Data); Primitive SchemaQuery; switch (Engines.CurrentEngine) { case Engines.EnginesMode.SQLITE: Engines.SQLite SQLite = new Engines.SQLite(); Engines.QuerySettings QS = new Engines.QuerySettings { Database = Engines.CurrentDatabase, SQL = SQLite.GetColumnsOfTable(Engines.CurrentTable), FetchRecords = true, User = GlobalStatic.UserName, Explanation = "SCHEMA" }; SchemaQuery = Engines.Query(QS); break; default: throw new PlatformNotSupportedException("Currently database is not supported"); } Dictionary <string, bool> PK = Export.SQL_Fetch_PK(SchemaQuery, Schema, Engines.CurrentEngine); Dictionary <string, string> Types = Export.SQL_Fetch_Type(SchemaQuery, Schema, Engines.CurrentEngine); Export.SQL(Data, Schema, PK, Types, Engines.CurrentTable, Path); LDProcess.Start(Path, null); Events.LogMessagePopUp("SQL export of " + Engines.CurrentTable + " completed!", Language.Localization["Export"], Language.Localization["Success"]); //TODO Localize Stack.Exit(StackPointer); return; } Events.LogMessagePopUp(Language.Localization["Error Generic"], Language.Localization["UI"], "Export.SQL");//TODO Localize Stack.Exit(StackPointer); return; } else if (Item == Language.Localization["CSV"] + " ") { string Path = LDDialogs.SaveFile("csv", null); if (!string.IsNullOrWhiteSpace(Path)) { Primitive Data = Export.Generate2DArrayFromLastQuery(); Export.CSV(Data, Export.GenerateSchemaFromQueryData(Data), Path, GlobalStatic.Deliminator); Events.LogMessagePopUp("CSV export of " + Engines.CurrentTable + " completed!", Language.Localization["Export"], Language.Localization["Success"]); //TODO Localize Stack.Exit(StackPointer); return; } Events.LogMessagePopUp(Language.Localization["Error Generic"], Language.Localization["UI"], "Export.CSV");//TODO Localize Stack.Exit(StackPointer); } else if (Item == "JSON") //TODO Localize { string Path = LDDialogs.SaveFile("json", null); if (!string.IsNullOrWhiteSpace(Path)) { Primitive Data = Export.Generate2DArrayFromLastQuery(); Export.JSON(Data, Export.GenerateSchemaFromQueryData(Data), Engines.CurrentTable.SanitizeFieldName(), Path); Events.LogMessagePopUp("JSON export of " + Engines.CurrentTable + " completed!", Language.Localization["Export"], Language.Localization["Success"]); //TODO Localize Stack.Exit(StackPointer); return; } Events.LogMessagePopUp(Language.Localization["Error Generic"], Language.Localization["UI"], "Export.JSON");//TODO Localize Stack.Exit(StackPointer); } else if (Item == "MarkDown") //TODO Localize { string Path = LDDialogs.SaveFile("md", null); if (!string.IsNullOrWhiteSpace(Path)) { Primitive Data = Export.Generate2DArrayFromLastQuery(); Export.MarkDown(Data, Export.GenerateSchemaFromQueryData(Data), Path); Events.LogMessagePopUp("MarkDown export is now complete", Language.Localization["Export"], Language.Localization["Success"]); //TODO Localize Stack.Exit(StackPointer); return; } Events.LogMessagePopUp(Language.Localization["Error Generic"], Language.Localization["UI"], "Export.MarkDown");//TODO Localize Stack.Exit(StackPointer); } else if (Item == "Wiki MarkUp") //TODO Localize { string Path = LDDialogs.SaveFile("markup", null); if (!string.IsNullOrWhiteSpace(Path)) { Primitive Data = Export.Generate2DArrayFromLastQuery(); Export.MarkUp(Data, Export.GenerateSchemaFromQueryData(Data), Path); Events.LogMessagePopUp("Wiki Markup export is now complete", Language.Localization["Export"], Language.Localization["Success"]); //TODO Localize Stack.Exit(StackPointer); return; } Events.LogMessagePopUp(Language.Localization["Error Generic"], Language.Localization["UI"], "Export.Wiki Markup");//TODO Localize Stack.Exit(StackPointer); } else if (Item == "Excel") //TODO Localize { string Path = LDDialogs.SaveFile("xlsx", null); if (!string.IsNullOrWhiteSpace(Path)) { Primitive Data = Export.Generate2DArrayFromLastQuery(); //Export.Excel(Data, Export.GenerateSchemaFromQueryData(Data), Engines.CurrentTable, Path); Events.LogMessagePopUp("Excel export is now complete", Language.Localization["Export"], Language.Localization["Success"]); //TODO Localize Stack.Exit(StackPointer); return; } Events.LogMessagePopUp(Language.Localization["Error Generic"], Language.Localization["UI"], "Export.Excel Markup");//TODO Localize Stack.Exit(StackPointer); } //Settings else if (Item == Language.Localization["About"]) { Engines.QuerySettings QS = new Engines.QuerySettings { Database = Engines.CurrentDatabase, SQL = "SELECT SQLITE_VERSION(),sqlite_source_id();", FetchRecords = true, User = GlobalStatic.UserName, Explanation = Language.Localization["User Requested"] + ":" + Language.Localization["App"] }; Primitive About_Data = Engines.Query(QS); string About_Msg = string.Format("DBM C# is a Database Mangement Program developed by Abhishek Sathiabalan. (C){0}. All rights reserved.\n\nYou are running : {1} v{2}\n\n", GlobalStatic.Copyright, GlobalStatic.ProductID, GlobalStatic.VersionID); About_Msg += string.Format("SQLite Version : {0}\nSQLITE Source ID : {1}", About_Data[1]["SQLITE_VERSION()"], About_Data[1]["sqlite_source_id()"]); Events.LogMessagePopUp(About_Msg, "Debug", "About");//DO NOT LOCALIZE Stack.Exit(StackPointer); return; } else if (Item == Language.Localization["Show Help"]) { string Path = System.IO.Path.Combine(GlobalStatic.AssetPath, "HELP Table.html"); LDProcess.Start(Path, null); Stack.Exit(StackPointer); return; } else if (Item == Language.Localization["Settings Editor"]) { UI.Settings.Display(); Stack.Exit(StackPointer); return; } else if (Item == Language.Localization["Refresh Schema"]) { Engines.GetSchema(Engines.CurrentDatabase); Engines.GetColumnsofTable(Engines.CurrentDatabase, Engines.CurrentTable); Stack.Exit(StackPointer); return; } else if (Item == Language.Localization["Check for Updates"]) { Updater.CheckForUpdates(GlobalStatic.UpdaterDBpath); Stack.Exit(StackPointer); return; } //Charts else if (Item == "Bar") //TODO Localize { Google_Charts.Chart.Bar Bar = new Google_Charts.Chart.Bar(); UI.Charts.Display(Bar); Stack.Exit(StackPointer); return; } else if (Item == "Column") //TODO Localize { Google_Charts.Chart.Column Column = new Google_Charts.Chart.Column(); UI.Charts.Display(Column); Stack.Exit(StackPointer); return; } else if (Item == "Geo") //TODO Localize { Google_Charts.Chart.GeoCharts Geo = new Google_Charts.Chart.GeoCharts(); UI.Charts.Display(Geo); Stack.Exit(StackPointer); return; } else if (Item == "Histogram") //TODO Localize { Google_Charts.Chart.Histograms Histo = new Google_Charts.Chart.Histograms(); UI.Charts.Display(Histo); Stack.Exit(StackPointer); return; } else if (Item == "Line") //TODO Localize { Google_Charts.Chart.Line Line = new Google_Charts.Chart.Line(); UI.Charts.Display(Line); Stack.Exit(StackPointer); return; } else if (Item == "Org") //TODO Localize { Google_Charts.Chart.OrgChart Org = new Google_Charts.Chart.OrgChart(); UI.Charts.Display(Org); Stack.Exit(StackPointer); return; } else if (Item == "Pie") //TODO: Localize { Google_Charts.Chart.Pie Pie = new Google_Charts.Chart.Pie(); UI.Charts.Display(Pie); Stack.Exit(StackPointer); return; } else if (Item == "Sankey") //TODO Localize { Google_Charts.Chart.SanKey SanKey = new Google_Charts.Chart.SanKey(); UI.Charts.Display(SanKey); Stack.Exit(StackPointer); return; } else if (Item == "Scatter Plot") //TODO Localize { Google_Charts.Chart.Scatter Scatter = new Google_Charts.Chart.Scatter(); UI.Charts.Display(Scatter); Stack.Exit(StackPointer); return; } else if (Item == "Sortable Table") //TODO Localize { Google_Charts.Chart.Table Table = new Google_Charts.Chart.Table(); UI.Charts.Display(Table); Stack.Exit(StackPointer); return; } else if (Item == "TimeLine") //TODO Localize { Google_Charts.Chart.TimeLine TL = new Google_Charts.Chart.TimeLine(); UI.Charts.Display(TL); Stack.Exit(StackPointer); return; } else if (Item != null) { Events.LogMessage(Item + " does not exist in context or is not yet implemented", Language.Localization["UI"]); } Stack.Exit(StackPointer); }