public static void Display(Google_Charts.Chart chart) { int StackPointer = Stack.Add("UI.Charts.Display()"); Charts.chart = chart; ClearWindow(); GraphicsWindow.Title = "Charts"; LDGraphicsWindow.CancelClose = true; LDGraphicsWindow.ExitOnClose = false; LDGraphicsWindow.Closing += Events.Closing; LDGraphicsWindow.ExitButtonMode(GraphicsWindow.Title, "Disabled"); XColumns.Clear(); YColumns.Clear(); Schema = Export.GenerateSchemaListFromLastQuery(); //UI Stuff GraphicsWindow.FontSize = GlobalStatic.DefaultFontSize + 12; GraphicsWindow.DrawText(5, 10, string.Format("Min Columns {0}", chart.MinColumns)); GraphicsWindow.DrawText(5, 30, string.Format("Max Columns {0}", chart.MaxColumns)); Inequality = Shapes.AddText("Equation"); Shapes.Move(Inequality, 400, 5); GraphicsWindow.DrawText(5, 70, "X:"); GraphicsWindow.DrawText(300 + 100, 70, "Columns:"); GraphicsWindow.DrawText(600 + 200, 70, "Y:"); GraphicsWindow.DrawText(5, 450, "Title"); GraphicsWindow.DrawText(5, 500, "SubTitle"); GraphicsWindow.DrawText(5, 550, "X axis"); GraphicsWindow.DrawText(5, 600, "Y axis"); GraphicsWindow.FontSize = GlobalStatic.DefaultFontSize; XListBox = LDControls.AddListBox("", 300, 300); SchemaListBox = LDControls.AddListBox(Schema.ToPrimitiveArray(), 300, 300); YListBox = LDControls.AddListBox("", 300, 300); DataView = LDControls.AddDataView(300, 300, "1=Column;2=Type;"); LDControls.DataViewSetColumnComboBox(DataView, 2, "1=Text;2=Number;"); if (Desktop.Width < 1500) { LDScrollBars.Add(1920, 0); } Controls.Move(XListBox, 5, 100); Controls.Move(SchemaListBox, 300 + 100, 100); Controls.Move(YListBox, 600 + 200, 100); Controls.Move(DataView, 1200, 100); Left1 = Controls.AddButton("<", 325, 200); Right1 = Controls.AddButton(">", 325, 250); Left2 = Controls.AddButton("<", 725, 200); Right2 = Controls.AddButton(">", 725, 250); GenerateChartButton = Controls.AddButton("Generate Chart", 300, 500); Controls.Move(GenerateChartButton, 800, 550); Controls.SetSize(GenerateChartButton, 100, 30); //TODO Add TextBoxes for Title,SubTitle,X axis caption, and y axis caption TitleTB = Controls.AddTextBox(130, 450); SubTitleTB = Controls.AddTextBox(130, 500); XaxisCaptionTB = Controls.AddTextBox(130, 550); YaxisCaptionTB = Controls.AddTextBox(130, 600); Controls.SetSize(TitleTB, 200, 30); Controls.SetSize(SubTitleTB, 200, 30); Controls.SetSize(XaxisCaptionTB, 200, 30); Controls.SetSize(YaxisCaptionTB, 200, 30); Escape = Controls.AddButton("Esc", 50, 500); Controls.Move(Escape, 800, 500); Controls.SetSize(Escape, 100, 30); //TODO Add Region options for GeoCharts //TODO Allow users to specify data type (Number,string,eventually Datetime etc). //Otherwise attempt to grab that data from the db? Controls.SetSize(Left1, 50, 30); Controls.SetSize(Right1, 50, 30); Controls.SetSize(Left2, 50, 30); Controls.SetSize(Right2, 50, 30); //Event Handler Unhooking Controls.ButtonClicked -= Events.BC; //Event Handler Hooking Controls.ButtonClicked += Handler; AutoHide(); 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); }