コード例 #1
0
ファイル: ConnectionForm.cs プロジェクト: StefH/MyDbUtils
        private void btnSelectConfig_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK == openFileDialog.ShowDialog())
            {
                var xmlConfig = new XmlConfig
                {
                    ConfigFile = openFileDialog.FileName
                };

                List <string> connections = xmlConfig.GetChildElements("//connectionStrings", "connectionString");

                if (connections.Count > 0)
                {
                    var frm = new SaveConnectionAsForm();
                    if (DialogResult.OK == frm.ShowDialog())
                    {
                        XmlConfig.Instance.SetValue("//MyConnectionStrings//add[@key='" + frm.ConnectionName + "']", connections[0]);
                        DialogResult = DialogResult.OK;
                    }
                }
                else
                {
                    MessageBox.Show("No connection string found in this configuration file.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                Close();
            }
        }
コード例 #2
0
ファイル: ConnectionForm.cs プロジェクト: StefH/MyDbUtils
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (rbConnectionString.Checked)
            {
                _connectionString = txtConnectionString.Text;
            }

            var frm = new SaveConnectionAsForm();

            if (DialogResult.OK == frm.ShowDialog())
            {
                XmlConfig.Instance.SetValue("//MyConnectionStrings//add[@key='" + frm.ConnectionName + "']", _connectionString);
            }

            Close();
        }