Exemple #1
0
        /// <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);
        }
Exemple #2
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            //  desable open other forms
            EnableFrm = false;

            // get server info ==> server , user , pass
            string strServer = cmbServer.Text, strUser = txtUser.Text, strPass = txtPass.Text;


            //  create sql connection
            sqlConnection = sqlfunction.SqlConnect(strServer, strUser, strPass);

            //  test sql connection
            if (sqlfunction.SqlConnectionTest(sqlConnection))
            {
                #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 = lstSvrName(strPathLoginFolder);
                }

                #endregion


                //  load database name  // set source cmbDBNames
                cmbDBNames.DataSource = sqlfunction.SqlGetDBName(sqlConnection);

                // set btnConnect text
                btnConnect.Text = "اتصال مجدد";

                //  enable open other forms
                EnableFrm = true;
            }

            else   //   if problem in sql connection
            {
                MessageBox.Show("عدم برقراری ارتباط", "!هشدار");
                btnConnect.Text = "اتصال";

                //  desable open other forms
                EnableFrm = false;
            }

            Cursor.Current = Cursors.Default;
        }