private void buttonOK_Click(object sender, EventArgs e) { string oldTableName = textBoxOldTableName.Text; string newTableName = textBoxNewTableName.Text; List <string> updatesToPerform = new List <string>(); for (int i = 0; i < listBoxRemoteAttributes.SelectedItems.Count; i++) { RemoteAttribute current = ((RemoteAttribute)listBoxRemoteAttributes.SelectedItems[i]); string attributeName = current.AttributeName; string viewStmt = current.SqlView; if (viewStmt.Contains(oldTableName)) { // Perform the update. viewStmt = viewStmt.Replace(oldTableName, newTableName); string update = "UPDATE ATTRIBUTES_ SET SQLVIEW = '" + viewStmt + "' WHERE ATTRIBUTE_ = '" + attributeName + "' AND NETWORK_DEFINITION_NAME = '" + _netDefName + "'"; // Drop and recreate the views. // TODO: Will have to create special tables/views for all ATTRIBUTES and ASSETS when creating remote or native attributes in the system. The tables/views created will need to include // the network definition that the attribute belongs to. Alternate option is to move to remote data only, and handle everything from the ATTRIBUTES_ table. // TODO: Hook up SQLVIEW text window to ATTRIBUTES_. string dropView = "DROP VIEW " + attributeName + ""; updatesToPerform.Add(dropView); string createView = "CREATE VIEW " + attributeName + " AS " + viewStmt; updatesToPerform.Add(createView); updatesToPerform.Add(update); } else { //MessageBox.Show("Could not find old table name in SQL VIEW statement. Please check the name and try again.", "Alter Attribute Failed"); Global.WriteOutput("Could not find old table name in SQL VIEW statement for attribute " + attributeName + "."); //foundMismatch = true; } } //DBMgr.ExecuteBatchNonQuery(updatesToPerform); foreach (string update in updatesToPerform) { try { DBMgr.ExecuteNonQuery(update); //Global.WriteOutput("Updated: " + update); } catch (Exception exc) { Global.WriteOutput("Error processing update. " + update); } } this.Close(); }
private void updateToolStripMenuItem_Click(object sender, EventArgs e) { RemoteAttribute selectedAttribute = ((RemoteAttribute)listBoxRemoteAttributes.SelectedItem); string update = "UPDATE ATTRIBUTES_ SET SQLVIEW = '" + textBoxSQLView.Text + "' WHERE ATTRIBUTE_ = '" + selectedAttribute.AttributeName; string dropView = "DROP VIEW " + selectedAttribute.AttributeName; string createView = "CREATE VIEW " + selectedAttribute.AttributeName + " AS " + textBoxSQLView.Text; try { DBMgr.ExecuteNonQuery(update); DBMgr.ExecuteNonQuery(dropView); DBMgr.ExecuteNonQuery(createView); } catch (Exception exc) { Global.WriteOutput("Error updating VIEW. " + exc.Message); } }