/// <summary> /// serverUserPass /// </summary> /// <param name="loginPath">مسیر فایل اطلاعات ورود به سرور</param> /// <param name="strServer">سرور</param> /// <returns>لیست شامل نام سرور ، نام کاربری و رمز عبور سرور</returns> public List <string> ServerUserPass(string loginPath, string strServer) { // return list List <string> lst = new List <string>(); lst.Add(strServer); // add server // all servers login info List <string> lstLogin = new List <string>(); lstLogin = ReadTxt(loginPath); // get this server user & pass add to lst for (int i = 0; i < lstLogin.Count; i++) { // find this server info if (lstLogin[i].Contains(strServer)) { // finde index of separator List <int> lstIndexOf = new List <int>(); lstIndexOf = IndexOfAll(lstLogin[i], ","); // add user & pass to lst lst.Add(lstLogin[i].Substring(lstIndexOf[0], (lstIndexOf[1] - lstIndexOf[0]) - 1)); lst.Add(lstLogin[i].Substring(lstIndexOf[1], lstLogin[i].Length - lstIndexOf[1])); } } // set user & pass when server is local if (strServer == ".") { lst[1] = lst[2] = ""; } // decrypt pass try { lst[2] = CryptorEngine.Decrypt(lst[2], true); } catch (Exception) { } return(lst); }
private void btnConnect_Click(object sender, EventArgs e) { // get server info ==> server , user , pass string strServer = cmbServer.Text, strUser = txtUser.Text, strPass = txtPass.Text; // create sql connection sqlCon = functions.SqlConnect(strServer, strUser, strPass); // test sql connection // result yes if (functions.TestConn(sqlCon)) { #region save login info with encrypt pass // save login info with encrypt pass if (chbRemember.CheckState == CheckState.Checked) { // encrypt pass string strPassEncrypt = CryptorEngine.Encrypt(strPass, true); List <string> lst = functions.ReadTxt(strPathLoginFolder); // save login when login file info is empty if (File.ReadAllText(strPathLoginFolder) == "") { File.WriteAllText(strPathLoginFolder, strServer + "," + strUser + "," + strPassEncrypt); } // save or replace login when login file info is not empty if (File.ReadAllText(strPathLoginFolder) != "") { int intFind = functions.ListFind(lst, strServer); if (intFind != -1) { lst[intFind] = strServer + "," + strUser + "," + strPassEncrypt; functions.SaveListToText(lst, strPathLoginFolder); } else { File.WriteAllText(strPathLoginFolder, File.ReadAllText(strPathLoginFolder) + "\r\n" + strServer + "," + strUser + "," + strPassEncrypt); } } // load server name cmbServer.DataSource = functions.ListServerName(strPathLoginFolder); } #endregion // load all database name // set source cmbDBNames functions.ComboBoxSource(cmbDB, functions.SqlGetDBName(sqlCon)); // list of all database name lstAllDataBases = functions.DataTableToList(functions.SqlGetDBName(sqlCon)); // set btnConnect text btnConnect.Text = "اتصال مجدد"; } // test sql connection // result no else { btnConnect.Text = "اتصال"; MessageBox.Show("عدم برقراری ارتباط", "!هشدار"); } //*********** defult!!!!!! cmbDB.Text = "_Main"; }