示例#1
0
        private void SetComBox()
        {
            ConfigObj = (DataBaseSection)ConfigurationManager.GetSection("DataBaseSections");
            comBoxLink.SelectedIndex = -1;
            comBoxLink.Properties.Items.Clear();
            var lstSettings = ConfigObj.Section.Cast <MyKeyValueSetting>();

            foreach (var item in lstSettings)
            {
                comBoxLink.Properties.Items.Add(item.name);
            }
        }
示例#2
0
        private void btnDelDataBase_Click(object sender, EventArgs e)
        {
            if (comBoxLink.SelectedIndex < 0)
            {
                MessageBox.Show("请选择数据链接!");
                return;
            }
            Configuration   config      = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            DataBaseSection currSection = (DataBaseSection)config.GetSection("DataBaseSections");

            currSection.Section.Remove(comBoxLink.SelectedItem.ToString());
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("DataBaseSections");
            SetComBox();
            MessageBox.Show("删除成功");
        }
示例#3
0
        private void btnAddDataBase_Click(object sender, EventArgs e)
        {
            if (edtName.Text == "")
            {
                MessageBox.Show("请输入链接名称");
                return;
            }
            if (edtServer.Text == "")
            {
                MessageBox.Show("请输入服务名");
                return;
            }
            if (edtDataBase.Text == "")
            {
                MessageBox.Show("请输入数据库名");
                return;
            }
            if (edtUserName.Text == "")
            {
                MessageBox.Show("请输入用户名");
                return;
            }
            if (comBoxLink.Properties.Items.Contains(edtName.Text))
            {
                MessageBox.Show("该链接名称已存在!");
                return;
            }
            string            sConnect   = "server=" + edtServer.Text + ";database=" + edtDataBase.Text + ";uid=" + edtUserName.Text + ";pwd=" + edtPassWord.Text;
            MyKeyValueSetting addSetting = new MyKeyValueSetting();

            addSetting.ConnectString = sConnect;
            addSetting.name          = edtName.Text;
            string[] sRetArray = GetStringArrayByList(gcDetail.DataSource as List <TableFields>);
            addSetting.table  = sRetArray[0];
            addSetting.column = sRetArray[1];

            Configuration   config      = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            DataBaseSection currSection = (DataBaseSection)config.GetSection("DataBaseSections");

            currSection.Section.Add(addSetting);
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("DataBaseSections");
            SetComBox();
            MessageBox.Show("添加成功");
        }