public ConnectionDialogue LoadConnection(String Company) { try { oldname = Company; txtName.EditValue = Company; Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); BL.Configuration.CompleteDistributionConfig section = config.GetSection("CompleteDistributionConfig") as BL.Configuration.CompleteDistributionConfig; BL.Configuration.RegisteredCompanyCollection companies = section.RegisteredCompanies; string connectionString = null; foreach (BL.Configuration.RegisteredCompany company in companies) { if (company.Name == Company) { connectionString = company.ConnectionString; txtTimeout.EditValue = Convert.ToInt32(company.ConnectionTimeout) / 1000; selectedCompany = company; chkUpdateLocation.Checked = company.UpdateSite.Value; break; } } SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString); ddlServer.EditValue = builder["Data Source"]; ddlDatabase.EditValue = builder["Initial Catalog"]; ddlAuthentication.SelectedIndex = Convert.ToBoolean(builder["Integrated Security"]) ? 0 : 1; if (ddlAuthentication.SelectedIndex != 0) { txtUsername.EditValue = builder["User ID"]; txtPassword.EditValue = builder["Password"]; } if (!String.IsNullOrEmpty(builder["AttachDBFilename"].ToString())) { btnDBFileLocation.Text = builder["AttachDBFilename"].ToString(); } return(this); } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } return(null); } }
//PLEASE NOTE THIS DOES NOT WORK THEN DEBUGGING private void btnAccept_Click(object sender, EventArgs e) { try { if (!dxValidationProvider.Validate()) { return; } Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigurationSection section = (ConfigurationSection)config.GetSection("CompleteDistributionConfig"); section.LockItem = false; BL.Configuration.RegisteredCompanyCollection companies = (BL.Configuration.RegisteredCompanyCollection)((BL.Configuration.CompleteDistributionConfig)(section)).RegisteredCompanies; //Null then New button was clicked if (oldname == null) { //NEW Entity Framwork requires the a different connection string format so we save the individual //TODO: Chekc last Param companies.NewCompany(txtName.Text, GetConnectionString(false), Convert.ToString(Convert.ToInt32(txtTimeout.EditValue) * 1000), chkUpdateLocation.Checked);//, GetEntityConnectionString(false), GetEntityConnectionString(false)); foreach (BL.Configuration.RegisteredCompany company in companies) { if (company.Name == txtName.Text) { selectedCompany = company; if (companies.Count == 1) { chkUpdateLocation.Checked = true; } break; } } } else { companies[oldname].Name = txtName.Text; companies[txtName.Text].ConnectionString = GetConnectionString(false); companies[txtName.Text].ConnectionTimeout = Convert.ToString(Convert.ToInt32(txtTimeout.EditValue) * 1000); // Set connection string properties for Entity framework conenction string //companies[txtName.Text].EntityTablesConnectionString = GetEntityConnectionString(false); //TODO: Make oce for Views Modle //companies[txtName.Text].EntityViewsConnectionString = GetEntityConnectionString(false); } if (selectedCompany.UpdateSite.Value) { foreach (BL.Configuration.RegisteredCompany company in companies) { if (selectedCompany.Name != company.Name) { company.UpdateSite = false; } else { company.UpdateSite = true; } } } config.Save(ConfigurationSaveMode.Modified); this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } }