private async void ts_save_sql_Click(object sender, EventArgs e) { if (!structLoaded) { MessageBox.Show("You can not do that until a structure has been loaded!", "Structure Exception", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } string tablename = core.TableName; if (string.IsNullOrEmpty(tablename)) { DialogResult result = MessageBox.Show("It seems the structure lua does not have a table name listed, would you like to define one?", "Input Required", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (result) { case DialogResult.Cancel: return; case DialogResult.No: return; case DialogResult.Yes: using (GUI.InputBox input = new GUI.InputBox("Enter desired table name", false)) { if (input.ShowDialog(this) != DialogResult.OK) { return; } lManager.Enter(Logs.Sender.RDB, Logs.Level.WARNING, "User opted to provide Table name for save operation.\n\t- Table name provided: {0}", input.Value); tablename = input.Value; } break; } } Database dManager = new Database(); try { await Task.Run(() => { dManager.ExportToTable(tablename, tManager.RDBCore.Data); }); } catch (System.Data.SqlClient.SqlException ex) { lManager.Enter(Logs.Sender.RDB, Logs.Level.SQL_ERROR, ex); return; } catch (Exception ex) { lManager.Enter(Logs.Sender.RDB, Logs.Level.ERROR, ex); return; } finally { lManager.Enter(Logs.Sender.RDB, Logs.Level.NOTICE, "{0} rows were saved to table: {1} from tab: {2}", tManager.RDBCore.RowCount, tablename, tManager.Text); } }
public async void TS_Save_File_Click(object sender, EventArgs e) { string buildPath = null; if (core is null) { MessageBox.Show("You cannot do that without having loaded data first!", "Save File Exception", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } try { string filename = core.FileName; if (string.IsNullOrEmpty(filename)) { DialogResult result = MessageBox.Show("It seems the structure lua does not have a filename listed, would you like to define one?\n\nReminder: Choosing no will cause me use this tabs name instead!", "Input Required", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (result) { case DialogResult.Cancel: return; case DialogResult.No: lManager.Enter(Logs.Sender.RDB, Logs.Level.DEBUG, "User opted to use the tab name as Filename for save operation.\n\t- Filename provided: {0}", tManager.Text); filename = string.Format("{0}.rdb", tManager.Text); break; case DialogResult.Yes: using (GUI.InputBox input = new GUI.InputBox("Enter desired filename", false)) { if (input.ShowDialog(this) != DialogResult.OK) { return; } lManager.Enter(Logs.Sender.RDB, Logs.Level.DEBUG, "User opted to provide Filename for save operation.\n\t- Filename provided: {0}", input.Value); filename = input.Value; } break; } } if (!filename.Contains("ascii") && ts_save_w_ascii.Checked) { filename = string.Format(@"{0}(ascii).rdb", filename.Split('.')[0]); } if (ts_save_enc.Checked) { filename = DataCore.Functions.StringCipher.Encode(filename); } buildPath = string.Format(@"{0}\{1}", buildDir, filename); if (!Directory.Exists(buildDir)) { Directory.CreateDirectory(buildDir); } if (File.Exists(buildPath)) { File.Delete(buildPath); } await Task.Run(() => { core.RdbPath = buildPath; core.Write(); }); } catch (Exception ex) { MessageBox.Show(ex.Message, "RDB Save Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); lManager.Enter(Logs.Sender.RDB, Logs.Level.ERROR, ex); } finally { lManager.Enter(Logs.Sender.RDB, Logs.Level.NOTICE, "{0} entries written from tab: {1} into file: {2}", core.RowCount, tManager.Text, buildPath); } }
private async void ts_load_sql_Click(object sender, EventArgs e) { if (!structLoaded) { MessageBox.Show("You can not do that until a structure has been loaded!", "Structure Exception", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } string tablename = core.TableName; if (string.IsNullOrEmpty(tablename)) { DialogResult result = MessageBox.Show("It seems the structure lua does not have a table name listed, would you like to define one?", "Input Required", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (result) { case DialogResult.Cancel: return; case DialogResult.No: return; case DialogResult.Yes: using (GUI.InputBox input = new GUI.InputBox("Enter desired table name", false)) { if (input.ShowDialog(this) != DialogResult.OK) { return; } lManager.Enter(Logs.Sender.RDB, Logs.Level.WARNING, "User opted to provide Table name for load operation.\n\t- Table name provided: {0}", input.Value); tablename = input.Value; } break; } } dManager = new Database(); int rowCount = dManager.FetchRowCount(tablename); Daedalus.Structures.Row[] table_data = new Daedalus.Structures.Row[0]; try { await Task.Run(() => { table_data = dManager.FetchTable(rowCount, tablename); }); if (table_data.Length == 0) { lManager.Enter(Logs.Sender.RDB, Logs.Level.ERROR, "No results were loaded from the table!"); return; } core.SetData(table_data); } catch (System.Data.SqlClient.SqlException ex) { lManager.Enter(Logs.Sender.RDB, Logs.Level.SQL_ERROR, ex); return; } catch (Exception ex) { lManager.Enter(Logs.Sender.RDB, Logs.Level.ERROR, ex); return; } finally { lManager.Enter(Logs.Sender.RDB, Logs.Level.NOTICE, "{0} rows were loaded from table: {1} into tab: {2}", table_data.Length, tablename, tManager.Text); tManager.Text = Path.GetFileNameWithoutExtension(tablename); initializeGrid(); } }