Exemple #1
0
 private void GetSection(string sName)
 {
     if (ConfigObj != null)
     {
         MyKeyValueSetting oneSetting = ConfigObj.Section[sName];
         //解析connectionstring,server=WINDYCOMPUTER\TESTDB;database=CIS_TEST;uid=sa;pwd=winning
         //edtShowFields.Text = oneSetting.column;
         //edtShowTable.Text = oneSetting.table;
         SetConnectString(oneSetting.ConnectString);
         //表格
         gcShow.DataSource = null;
         gcShow.RefreshDataSource();
         List <TableFields> showData   = new List <TableFields>();
         string[]           tableArray = oneSetting.table.Split(';');
         string[]           fieldArray = oneSetting.column.Split(';');
         for (int i = 0; i < tableArray.Length; i++)
         {
             TableFields item = new TableFields();
             item.sTableName = tableArray[i];
             item.sFields    = fieldArray[i];
             showData.Add(item);
         }
         gcShow.DataSource = showData;
         gcShow.RefreshDataSource();
     }
 }
Exemple #2
0
 private void btnSure_Click(object sender, EventArgs e)
 {
     if (comBoxLink.SelectedIndex < 0)
     {
         MessageBox.Show("请选择数据链接!");
         return;
     }
     currConnection    = ConfigObj.Section[comBoxLink.SelectedItem.ToString()];
     this.DialogResult = DialogResult.OK;
     this.Close();
 }
Exemple #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("添加成功");
        }
 // 说明:如果不需要在代码中修改集合,可以不实现Add, Clear, Remove
 public void Add(MyKeyValueSetting setting)
 {
     this.BaseAdd(setting);
 }