Example #1
0
        public void WriteConfig(WebConfigData config)
        {
            var allConfigs     = GetConfigsList();
            var registryConfig = allConfigs.FirstOrDefault(c => c.DataSource == config.DataSource);

            if (registryConfig != null)
            {
                SetValue($"{BaseCatalog}_{registryConfig.Id}", config.BaseCatalog);
                SetValue($"{InitialCatalog}_{registryConfig.Id}", config.InitialCatalog);
            }
            else
            {
                int index = allConfigs.Count();
                if (index < TotalConfigs)
                {
                    SetValue($"{DataSource}_{index}", config.DataSource);
                    SetValue($"{BaseCatalog}_{index}", config.BaseCatalog);
                    SetValue($"{InitialCatalog}_{index}", config.InitialCatalog);
                }
                else
                {
                    index -= 1;
                    SetValue($"{DataSource}_{index}", config.DataSource);
                    SetValue($"{BaseCatalog}_{index}", config.BaseCatalog);
                    SetValue($"{InitialCatalog}_{index}", config.InitialCatalog);
                }
            }
        }
Example #2
0
        private void txtSource_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData != Keys.Enter)
            {
                return;
            }

            try
            {
                WebConfigData selectData = webConfigList.First(w => w.DataSource == txtSource.Text);
                txtBase.Text = selectData.BaseCatalog;
                txtInit.Text = selectData.InitialCatalog;
                SelectNextControl((Control)sender, true, true, true, true);
            }
            catch (Exception) {}
        }
Example #3
0
        public WebConfigData ReadConfig()
        {
            var result = new WebConfigData();

            var appSettings = doc.Root.Element("appSettings");
            var adds        = appSettings.Descendants("add").ToList();

            if (adds != null)
            {
                result.DataSource = adds.First(x => x.Attribute("key").Value == "DataSource")
                                    .Attribute("value").Value;
                result.InitialCatalog = adds.First(x => x.Attribute("key").Value == "InitialCatalog")
                                        .Attribute("value").Value;
                result.BaseCatalog = adds.First(x => x.Attribute("key").Value == "BaseCatalog")
                                     .Attribute("value").Value;
            }

            return(result);
        }