private void MainForm_Load(object sender, EventArgs e) { if (Settings.Default.MainWindowWidth >= 100 && Settings.Default.MainWindowHeight > 100) { Width = Settings.Default.MainWindowWidth; Height = Settings.Default.MainWindowHeight; } InitObjectsList(); txtSearchQuery.Focus(); if (Settings.Default.Server != "" && Settings.Default.Database != "") { var connRes = DataProvider.AddMSSqlManager("default", new MSSQLConnectionParams() { Server = Settings.Default.Server, Database = Settings.Default.Database, Username = Settings.Default.Username, Password = Settings.Default.Password, SetIntegratedSecurity = Settings.Default.IntegratedSecurity }); //connRes = DataProvider.AddMySqlManager("mysql", new MySqlConnectionParams() //{ // Server = "127.0.0.1", // Database = "skype", // Username = "******", // Password = null //}); DataProvider.SetActiveManager("default"); if (connRes.Success && DataProvider.ActiveManager.IsConnected) { lblStatus.Text = $"Connected {DataProvider.ActiveManager.ConnectionString}"; SearchInBackground(); return; } else { EasyMessageBox.Error(connRes.Exception.Message); } } lblStatus.Text = "Not Connected!"; lblLoading.Visible = false; }
private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { var results = e.Result as SearchResults; if (results == null) { return; } if (results.Error) { EasyMessageBox.Error(results.ErrorMessage); lblLoading.Visible = false; return; } foreach (var obj in results.FoundDbObjects) { var item = new ListViewItem(); item.Text = obj.ToString(); item.Tag = obj; if (DataProvider.ActiveManager.IsTable(obj)) { item.ImageIndex = 0; } if (DataProvider.ActiveManager.IsView(obj)) { item.ImageIndex = 1; } if (DataProvider.ActiveManager.IsStoredProcedure(obj)) { item.ImageIndex = 2; } listDbObjects.Items.Add(item); } lblObjectsCount.Text = results.FoundDbObjects != null ? results.FoundDbObjects.Count + " Objects" : ""; lblLoading.Visible = bw.IsBusy; txtSearchQuery.Focus(); }
private void SetConnection() { using (var connDialog = new ConnectionDialog()) { connDialog.Server = Settings.Default.Server; connDialog.Database = Settings.Default.Database; connDialog.Username = Settings.Default.Username; connDialog.IntegratedSecurity = Settings.Default.IntegratedSecurity; if (connDialog.ShowDialog() == DialogResult.OK) { var connRes = DataProvider.AddMSSqlManager("default", new MSSQLConnectionParams() { Server = connDialog.Server, Database = connDialog.Database, Username = connDialog.Username, Password = connDialog.Password, SetIntegratedSecurity = connDialog.IntegratedSecurity }); DataProvider.SetActiveManager("default"); if (connRes.Success && DataProvider.ActiveManager.IsConnected) { Settings.Default.Server = connDialog.Server; Settings.Default.Database = connDialog.Database; Settings.Default.Username = connDialog.Username; Settings.Default.Password = connDialog.Password; Settings.Default.IntegratedSecurity = connDialog.IntegratedSecurity; Settings.Default.Save(); lblStatus.Text = $"Connected {DataProvider.ActiveManager.ConnectionString}"; SearchInBackground(); } else { EasyMessageBox.Error(connRes.Exception.Message); lblStatus.Text = "Not Connected!"; } } } }
private void BackupSelectedScript() { if (listDbObjects.FocusedItem?.Tag != null) { var dbObject = listDbObjects.FocusedItem.Tag as IDbObject; if (DataProvider.ActiveManager.IsView(dbObject)) { dbObject = DataProvider.ActiveManager.View(dbObject); } else if (DataProvider.ActiveManager.IsStoredProcedure(dbObject)) { dbObject = DataProvider.ActiveManager.StoredProcedure(dbObject); } else { return; } Tuple <string, string> output; if (FileHelper.BackupScript(dbObject.Name, dbObject.Script, out output)) { EasyMessageBox.MessageWithActions( "Script saved", $"Script saved successfully.\r\n{output.Item1}", "OK", new ActionButton(() => Process.Start(output.Item1), "Open File"), new ActionButton(() => Process.Start(output.Item2), "Open Dir") ); } else { EasyMessageBox.Error($"Error occured while saving file.\n{output.Item1}"); } } }