public static Dictionary <string, string> SQL_Fetch_Type(Primitive SchemaQuery, Primitive Schema, Engines.EnginesMode CurrentEngine) { int StackPointer = Stack.Add("Export.SQL_Fetch_Type"); Engines.IEngine engine; switch (CurrentEngine) { case Engines.EnginesMode.SQLITE: engine = new Engines.SQLite(); break; default: throw new PlatformNotSupportedException("Current Engine is not supported"); } return(engine.GetTypes(SchemaQuery, Schema)); }
/// <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); }