private void btnDeleteQuery_Click(object sender, EventArgs e) { string SQL; int count; try { if (txtSQLQuery.Text == "") { MessageBox.Show("Kindly Write the Query first"); return; } //Check whether Database Coreutility exists on the SQL Server if (!(ClassCoreUtility.checkIfDatabaseExistsOnSQL("CoreUtility", cmbSQLServer.Text.ToString(), txtUserID.Text.ToString(), txtPassword.Text.ToString()))) { MessageBox.Show("Create Querylist table first!!"); return; } //Check if Query exists Querylist table SQL = "SELECT * FROM CoreUtility.dbo.QueryList WHERE Query='" + txtSQLQuery.Text + "';"; count = ClassCoreUtility.executeSQLSelect(SQL, this.server, txtUserID.Text, txtPassword.Text, cmbDatabases.Text); if (count == 0) { MessageBox.Show("Query not present in the QueryList table"); return; } //Delete Query in QueryList table SQL = ""; SQL += "DELETE FROM CoreUtility.dbo.QueryList WHERE Query='" + txtSQLQuery.Text + "'AND Comment='" + txtComment.Text + "';"; count = ClassCoreUtility.executeSQLInsertUpdate(SQL, this.server.ToString(), txtUserID.Text.ToString(), txtPassword.Text.ToString()); if (count != 0) { MessageBox.Show("Query deleted sucessfully"); btnLoadQueries.PerformClick(); txtComment.Text = ""; txtSQLQuery.Text = ""; } else { MessageBox.Show("Query not deleted, Try Again !!"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void btnValidateQuery_Click(object sender, EventArgs e) { string SQL; int count; try { if (txtSQLQuery.Text == "") { MessageBox.Show("Kindly load the Query first"); return; } //Check whether database is Core Database if (!(ClassCoreUtility.checkIfCoreDatabase(cmbDatabases.Text.ToString(), this.server.ToString(), txtUserID.Text.ToString(), txtPassword.Text.ToString()))) { MessageBox.Show("Selected Database not a Core Database!!"); return; } //Validate Query SQL = txtSQLQuery.Text; count = ClassCoreUtility.executeSQLSelect(SQL, this.server, txtUserID.Text, txtPassword.Text, cmbDatabases.Text); if (count == 1) { MessageBox.Show("Query validated sucessfully on SQL Server"); } if (count == 0) { MessageBox.Show("Query validated sucessfully on SQL Server"); } } catch (Exception ex) { MessageBox.Show("Error in Query. Correct your Query!!!"); } }
private void metrobtnDeleteDatabaseSQLServer_Click(object sender, EventArgs e) { try { DialogResult dialogResult = MessageBox.Show("Do you really want to delete the database from SQL server?", "Delete database", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { txtCurrentCoreLoginUsersss.Text = ""; cmbFullAccessUser.Text = string.Empty; if (string.IsNullOrEmpty(cmbDatabases.Text.ToString()) || string.IsNullOrEmpty(txtCoreAccountss.Text.ToString())) { MessageBox.Show("Please select Coredatabase and Account"); return; } string SQL; int count = 0; //Check whether Database exists on the SQL Server if (!(ClassCoreUtility.checkIfDatabaseExistsOnSQL(cmbDatabases.Text.ToString(), this.server.ToString(), txtUserID.Text.ToString(), txtPasswordsss.Text.ToString()))) { MessageBox.Show("Database does not exist on SQL Server"); return; } //Check whether account present in CORE if (!(ClassCoreUtility.checkIfAccountPresentInCore(txtCoreAccountss.Text.ToString(), this.server.ToString(), txtUserID.Text.ToString(), txtPasswordsss.Text.ToString(), cmbDatabases.Text.ToString()))) { MessageBox.Show("Account does not exist in Core! Please give correct Account"); return; } //Delete database from SQL Server SQL = "SELECT * FROM sys.databases WHERE name='" + cmbDatabases.Text + "';"; count = ClassCoreUtility.executeSQLSelect(SQL, this.server, txtUserID.Text, txtPasswordsss.Text, cmbDatabases.Text); if (count == 0) { MessageBox.Show("Database does not exist on SQL Server"); } SQL = ""; count = 0; SQL = " DROP DATABASE [" + cmbDatabases.Text + "];"; count = ClassCoreUtility.executeSQLInsertUpdate(SQL, this.server.ToString(), txtUserID.Text.ToString(), txtPasswordsss.Text.ToString()); if (count != 0) { MessageBox.Show("Database deleted sucessully from SQL Server"); } else { MessageBox.Show("Database not deleted"); } //Call connect databases button event explicitly btnConnectDB.PerformClick(); } } catch (Exception ex) { MessageBox.Show("Cannot delete database as it is in use. Kindly close all open connections on SQL Server!!"); } }
private void btnAddQuery_Click(object sender, EventArgs e) { string SQL; int count; try { if (txtSQLQuery.Text == "") { MessageBox.Show("Kindly Write the Query first"); return; } //Check whether Database Coreutility exists on the SQL Server if (!(ClassCoreUtility.checkIfDatabaseExistsOnSQL("CoreUtility", cmbSQLServer.Text.ToString(), txtUserID.Text.ToString(), txtPassword.Text.ToString()))) { MessageBox.Show("Create Querylist table first!!"); return; } //Check if Query already added to Querylist table SQL = "SELECT * FROM CoreUtility.dbo.QueryList WHERE Query='" + txtSQLQuery.Text + "';"; count = ClassCoreUtility.executeSQLSelect(SQL, this.server, txtUserID.Text, txtPassword.Text, cmbDatabases.Text); if (count == 1) { MessageBox.Show("Query already added to QueryList table"); return; } //Check if Comment already used in Querylist table SQL = ""; SQL = "SELECT * FROM CoreUtility.dbo.QueryList WHERE Comment='" + txtComment.Text + "';"; count = ClassCoreUtility.executeSQLSelect(SQL, this.server, txtUserID.Text, txtPassword.Text, cmbDatabases.Text); if (count == 1) { MessageBox.Show("Comment already usedin QueryList table. Please choose different comment!!"); return; } //Validate Query SQL = ""; SQL = txtSQLQuery.Text; count = ClassCoreUtility.executeSQLSelect(SQL, this.server, txtUserID.Text, txtPassword.Text, cmbDatabases.Text); //Insert Query in QueryList table SQL = ""; SQL += "INSERT INTO CoreUtility. dbo.QueryList(Query,Comment,Software,IsActive) VALUES( '" + txtSQLQuery.Text + "','" + txtComment.Text + "','CORE',1);"; count = ClassCoreUtility.executeSQLInsertUpdate(SQL, this.server.ToString(), txtUserID.Text.ToString(), txtPassword.Text.ToString()); if (count != 0) { MessageBox.Show("Query added sucessfully"); btnLoadQueries.PerformClick(); txtComment.Text = ""; txtSQLQuery.Text = ""; } else { MessageBox.Show("Query not added, Try Again !!"); } } catch (Exception ex) { MessageBox.Show("Error in Query.Kindly correct youq query first"); } }