/// <summary> /// GetDataSource /// </summary> /// <returns></returns> protected static DataSource GetDataSource(string sApplicationId) { try { DataSource ds = null; using (var xml = new XmlConfiguration(new DBLogonInfo(sApplicationId))) { if (xml.Read()) ds = new DataSource { Provider = xml.DBLogonInfo.Provider, ConnectionString = xml.DBLogonInfo.ConnectionString }; } return ds; } catch (Exception ex) { MessageBox.Show(ex.Message, @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return null; } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void btnSave_Click(object sender, EventArgs e) { DBLogonInfo obj; try { obj = new DBLogonInfo( txtApplicationId.Text.Trim(), txtProvider.Text.Trim(), CreateConnectionString()); } catch (ArgumentNullException ex) { MessageBox.Show(ex.Message, @"Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } using (var xml = new XmlConfiguration(obj)) if (xml.Write()) { ClearForm(); } }
/// <summary> /// Handles the Validated event of the txtApplicationId control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void txtApplicationId_Validated(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtApplicationId.Text.Trim())) return; using (var xml = new XmlConfiguration(new DBLogonInfo(txtApplicationId.Text.Trim()))) { if (xml.Read()) { txtProvider.Text = xml.DBLogonInfo.Provider; txtApplicationId.Enabled = false; string[] strConn = xml.DBLogonInfo.ConnectionString.Split(';'); foreach (var strItem in strConn.Select(s => s.Split('='))) { switch (strItem[0].Trim()) { case "server": txtServer.Text = strItem[1].Trim(); break; case "port": txtPort.Text = strItem[1].Trim(); break; case "user id": txtUserId.Text = strItem[1].Trim(); break; case "password": txtPassword.Text = strItem[1].Trim(); break; case "database": txtDatabase.Text = strItem[1].Trim(); break; } } } } }