Exemplo n.º 1
0
        public bool UpdateLogin( )
        {
            using (SqlConnection conn = _cp.CreateSqlConnection(true))
            {
                string serverVersion = DbCmd.QueryServerVersion(_cp);
                if (String.IsNullOrEmpty(serverVersion))
                {
                    MessageService.ShowError("Can not retreive server version!");
                    return(false);
                }

                if (cmbDb.Text != _defaultDb)
                {
                    DbCmd.ChangeDefaultDB(conn, serverVersion, _loginName, cmbDb.Text);
                }
                if (cmbLanguage.Text != _defaultLanguage)
                {
                    DbCmd.ChangeDefaultLanguage(conn, serverVersion, _loginName, cmbLanguage.Text);
                }

                bool   isinrole   = false;
                string serverrole = String.Empty;
                foreach (DataRow row in _tblRoles.Rows)
                {
                    if (row["ServerRole"] == null || row["ServerRole"].GetType() == null)
                    {
                        continue;
                    }
                    isinrole = (bool)row["isin"];
                    if (isinrole)
                    {
                        if (DbCmd.IsInServerRole(conn, _loginName, (string)row["ServerRole"]))
                        {
                            continue;
                        }
                        DbCmd.AddToServerRole(conn, _loginName, (string)row["ServerRole"]);
                    }
                    else
                    {
                        if (!DbCmd.IsInServerRole(conn, _loginName, (string)row["ServerRole"]))
                        {
                            continue;
                        }
                        DbCmd.DropServerRole(conn, _loginName, (string)row["ServerRole"]);
                    }
                }
            }
            return(true);
        }