/// <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 sqlConnect = Functions.SqlConnect(strServer, strUser, strPass); // test sql connection if (Functions.SqlConnectionTest(sqlConnect)) { #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.saveList(lst, strPathLoginFolder); } else { File.WriteAllText(strPathLoginFolder, File.ReadAllText(strPathLoginFolder) + "\r\n" + strServer + "," + strUser + "," + strPassEncrypt); } } // load server name cmbServer.DataSource = ServerName(strPathLoginFolder); } #endregion // load database name // set source cmbDBNames Functions.ComboBoxSource(cmbDBNames, Functions.SqlGetDBName(sqlConnect)); // load query names LoadQueryFileName(); // enable group box Query this.cmbDBNames.Enabled = this.grbQry.Enabled = true; // set btnConnect text btnConnect.Text = "اتصال مجدد"; // read roidad LoadRoidad(cmbRoidad); } else // if problem in sql connection { MessageBox.Show("عدم برقراری ارتباط", "!هشدار"); btnConnect.Text = "اتصال"; } if (cmbDBNames.Items.Count != 0) { cmbDBNames.DropDownWidth = DropDownWidth(cmbDBNames); } }