private void dbsComboBox_SelectedIndexChanged(object sender, EventArgs e) { this.tablesBox.Items.Clear(); this.colsView.Rows.Clear(); this.filterClauseTxtBox.Text = string.Empty; TargetDatabaseConfigElement db = WizardHelper.Instance.SyncConfigSection.Databases.GetElementAt(this.dbsComboBox.SelectedIndex); statusLbl.Visible = true; try { // Issue a query to get list of all tables using (SqlConnection conn = new SqlConnection(db.GetConnectionString())) { conn.Open(); SqlCommand cmd = new SqlCommand(WizardHelper.SELECT_TABLENAMES_QUERY, conn); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { string schema = reader.GetString(0); string tableName = reader.GetString(1); string fullName = string.Format("{0}.{1}", schema, tableName); string quotedTableName = string.Format("[{0}]", tableName); string quotedFullName = string.Format("[{0}].[{1}]", schema, tableName); if (IsTableNameValid(tableName)) { if (schema.Equals("dbo", StringComparison.OrdinalIgnoreCase)) { this.tablesBox.Items.Add(quotedTableName, (selectedScope.SyncTables.GetElement(quotedTableName) != null || selectedScope.SyncTables.GetElement(tableName) != null)); } else { this.tablesBox.Items.Add(quotedFullName, selectedScope.SyncTables.GetElement(quotedFullName) != null || selectedScope.SyncTables.GetElement(fullName) != null); } } } } } } catch (SqlException exp) { MessageBox.Show("Error in querying database. " + exp.Message, "Target Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { statusLbl.Visible = false; } }
private void tablesBox_ItemCheck(object sender, ItemCheckEventArgs e) { if (tablesBox.SelectedIndex > -1) { this.colsView.Rows.Clear(); string tableName = this.tablesBox.SelectedItem.ToString(); if (e.NewValue == CheckState.Unchecked) { // Remove it from the SyncTables collection selectedScope.SyncTables.Remove(tableName); this.filterClauseTxtBox.Text = string.Empty; } else if (e.NewValue == CheckState.Checked) { SyncTableConfigElement table = new SyncTableConfigElement(); table.Name = tableName; table.IncludeAllColumns = true; TargetDatabaseConfigElement db = WizardHelper.Instance.SyncConfigSection.Databases.GetElementAt(this.dbsComboBox.SelectedIndex); statusLbl.Visible = true; try { tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable(tableName, new SqlConnection(db.GetConnectionString())); // Issue a query to get list of all tables foreach (DbSyncColumnDescription col in tableDesc.Columns) { SyncColumnConfigElement colConfig = new SyncColumnConfigElement() { Name = col.UnquotedName, IsPrimaryKey = col.IsPrimaryKey, IsNullable = col.IsNullable, SqlType = col.Type, }; table.SyncColumns.Add(colConfig); } this.DisplaySyncTableDetails(table); } catch (SqlException exp) { MessageBox.Show("Error in querying database. " + exp.Message, "Target Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { statusLbl.Visible = false; } // Add it to the sync table list selectedScope.SyncTables.Add(table); } } }
private void dbListBox_SelectedIndexChanged(object sender, EventArgs e) { if (this.dbListBox.SelectedIndex != -1) { // When a TargetDatabase node is selected populate the values this.addMode = false; this.removeBtn.Enabled = true; this.editBtn.Enabled = true; TargetDatabaseConfigElement db = WizardHelper.Instance.SyncConfigSection.Databases.GetElementAt(this.dbListBox.SelectedIndex); this.useIntAuthRadioBtn.Checked = db.UseIntegratedAuth; this.useSqlAuthRadioBtn.Checked = !db.UseIntegratedAuth; this.cfgNameTxtBox.Text = db.Name; this.useIntAuthRadioBtn.Checked = db.UseIntegratedAuth; this.unameTxtBox.Text = db.UserName; this.pwdTextBox.Text = db.Password; this.dbServerTxtBox.Text = db.DbServer; this.dbNameTxtBox.Text = db.DbName; } }
private void saveBtn_Click(object sender, EventArgs e) { // First test connection if (TestConnection()) { // Now add this to the Target database list if (string.IsNullOrEmpty(cfgNameTxtBox.Text)) { MessageBox.Show("Please enter a valid name for Config Name.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); cfgNameTxtBox.Focus(); } if (addMode) { var db = new TargetDatabaseConfigElement { Name = cfgNameTxtBox.Text, UseIntegratedAuth = useIntAuthRadioBtn.Checked, UserName = unameTxtBox.Text, Password = pwdTextBox.Text, DbServer = dbServerTxtBox.Text, DbName = dbNameTxtBox.Text }; WizardHelper.Instance.SyncConfigSection.Databases.Add(db); ReadAndBindData(); } else { var db = WizardHelper.Instance.SyncConfigSection.Databases.GetElementAt(dbListBox.SelectedIndex); db.Name = cfgNameTxtBox.Text; db.UseIntegratedAuth = useIntAuthRadioBtn.Checked; db.UserName = unameTxtBox.Text; db.Password = pwdTextBox.Text; db.DbServer = dbServerTxtBox.Text; db.DbName = dbNameTxtBox.Text; } dbSettingsGrp.Enabled = false; } }
private void tablesBox_SelectedIndexChanged(object sender, EventArgs e) { this.filterClauseTxtBox.Text = string.Empty; SyncTableConfigElement table = selectedScope.SyncTables.GetElement(this.tablesBox.SelectedItem.ToString()); if (table != null) { this.colsView.Rows.Clear(); this.filterClauseTxtBox.Text = table.FilterClause; TargetDatabaseConfigElement db = WizardHelper.Instance.SyncConfigSection.Databases.GetElementAt(this.dbsComboBox.SelectedIndex); tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable(table.Name, new SqlConnection(db.GetConnectionString())); // Display the list of currently selected items this.DisplaySyncTableDetails(table); } else { colsView.Rows.Clear(); } }