private void bOk_Click(object sender, EventArgs e) { try { clDBInfo it = new clDBInfo(tbDBName.Text, cbServer.Text, tbDBPath.Text, tbUser.Text, tbPassword.Text); Properties.Settings.Default.Databases.Add(it.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); //throw; } }
/// <summary> /// Читаем настройки из ПК СП /// </summary> /// <param name="filepath">путь к серверной папки ПК СП</param> /// <returns></returns> public static List <clDBInfo> ReadExProdLST(string filepath) { try { // Create an instance of StreamReader to read from a file. // The using statement also closes the StreamReader. List <clDBInfo> res = new List <clDBInfo>(); using (StreamReader sr = new StreamReader(filepath + @"\ex_prod.lst", Encoding.Default)) { String l1, l2; l1 = l2 = ""; int i = 0; // Read and display lines from the file until the end of // the file is reached. while ((l2 = sr.ReadLine()) != null) { if ((++i % 2) == 0) { //we have l1 - name; and l2 - data for parse clDBInfo tmp = new clDBInfo(l1, null, null, null, null); string[] stmp = l2.Split(':'); switch (stmp.Length) { case 1: //only alias? tmp.DBpath = l2; tmp.Server = "localhost"; break; case 2: //1 : - server:alias or drive:path if (stmp[1][0].Equals('\\')) //not alias - path? { tmp.DBpath = l2; tmp.Server = "localhost"; } else { tmp.DBpath = stmp[1]; tmp.Server = stmp[0]; } break; case 3: //server:drive:path { tmp.Server = stmp[0]; tmp.DBpath = stmp[1] + ":" + stmp[2]; } break; default: break; } res.Add(tmp); } l1 = l2; } } using (StreamReader sr = new StreamReader(filepath + @"\baseparam.txt", Encoding.Default)) { String l2 = ""; // Read and display lines from the file until the end of // the file is reached. while ((l2 = sr.ReadLine()) != null) { if (l2.Contains("user_name=")) { l2 = l2.Replace("user_name=", ""); foreach (clDBInfo it in res) { it.User = l2; } } if (l2.Contains("password="******"password="******""); foreach (clDBInfo it in res) { it.Password = l2; } } } } return(res); } catch (Exception e) { // Let the user know what went wrong. MessageBox.Show(e.Message); return(null); } }