Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public override void OnAccountChanged()
        {
            Oltp.AccountRow value = Window.CurrentAccount;

            //..............................
            // Segments
            _tabSegmentsInitialized = false;
            _segmentValueTables     = new Dictionary <Oltp.SegmentRow, Oltp.SegmentValueDataTable>();

            Window.AsyncOperation(delegate()
            {
                using (OltpProxy proxy = new OltpProxy())
                {
                    _segmentTable = proxy.Service.Segment_Get(value.ID, false);
                    foreach (Oltp.SegmentRow segment in _segmentTable.Rows)
                    {
                        Oltp.SegmentValueDataTable values = proxy.Service.SegmentValue_Get(value.ID, segment.SegmentID);
                        Oltp.SegmentValueRow defaultRow   = values.NewSegmentValueRow();
                        defaultRow.AccountID = value.ID;
                        defaultRow.SegmentID = segment.SegmentID;
                        defaultRow.ValueID   = -1;
                        defaultRow.Value     = "(none)";
                        values.Rows.InsertAt(defaultRow, 0);
                        values.AcceptChanges();
                        _segmentValueTables.Add(segment, values);
                    }
                }
            },
                                  delegate()
            {
                GetCreatives(value, null, false);
            });
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="include"></param>
        private void GetPages(Oltp.AccountRow account, string filter, bool include)
        {
            Oltp.AccountRow currentAccount = account == null ? this.Window.CurrentAccount : account;

            if (currentAccount == null)
            {
                return;
            }

            OltpLogicClient proxy = new OltpLogicClient();

            using (proxy)
            {
                _pages = proxy.Service.Page_Get(currentAccount.ID, filter, include, -1);
            }

            // Get an empty new list
            if (_items == null)
            {
                _items = new ObservableCollection <DataRow>();
            }
            else
            {
                _items.Clear();
            }

            // Add all items
            foreach (DataRow r in _pages.Rows)
            {
                _items.Add(r);
            }

            _listTable.ListView.ItemsSource = _items;
        }
        /*=========================*/
        #endregion

        /// <summary>
        /// Appplies user's permissions to the menu. If account is null, then permission is checked
        /// for at least one account per page. If a page has no account allowed for it, is is made invisible.
        /// If a section has no visible pages, the entire section is made invisible.
        ///
        /// When account is not null, pages are enabled/disabled according to selected account.
        /// </summary>
        /// <param name="account"></param>
        public void ApplyPermissions(Oltp.AccountRow account)
        {
            for (int s = 0; s < _menuSections.Items.Count; s++)
            {
                XmlElement  section         = (XmlElement)_menuSections.Items[s];
                ListBoxItem sectionListItem = (ListBoxItem)_menuSections.ItemContainerGenerator.ContainerFromIndex(s);
                XmlNodeList sectionPages    = section.GetElementsByTagName("Page");
                ListBox     pagesListBox    = Visual.GetDescendant <ListBox>(sectionListItem);

                bool isSectionEnabled = false;
                for (int p = 0; p < sectionPages.Count; p++)
                {
                    XmlElement page = (XmlElement)sectionPages[p];

                    bool        isPageEnabled = MainWindow.Current.HasPermission(account, page);
                    ListBoxItem pageListItem  = (ListBoxItem)pagesListBox.ItemContainerGenerator.ContainerFromIndex(p);

                    if (account == null)
                    {
                        pageListItem.Visibility = isPageEnabled ? Visibility.Visible : Visibility.Collapsed;
                    }
                    else
                    {
                        pageListItem.IsEnabled = isPageEnabled;
                    }

                    isSectionEnabled = isSectionEnabled || isPageEnabled;
                }

                if (account == null)
                {
                    sectionListItem.Visibility = isSectionEnabled ? Visibility.Visible : Visibility.Collapsed;
                }
            }
        }
        public override bool OnAccountChanging(Oltp.AccountRow account)
        {
            if (this.HasChanges)
            {
                MessageBoxResult result = MessageBox.Show(
                    "Save changes?",
                    "Warning",
                    MessageBoxButton.YesNoCancel,
                    MessageBoxImage.Warning,
                    MessageBoxResult.Cancel);

                if (result == MessageBoxResult.Cancel)
                {
                    return(false);
                }

                if (result == MessageBoxResult.Yes)
                {
                    if (!SaveSettings())
                    {
                        return(false);
                    }
                }
                else
                {
                    if (Window.CurrentAccount != null)
                    {
                        Window.CurrentAccount.RejectChanges();
                    }
                }
            }

            return(true);
        }
        private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            if (_isAccountChanging)
            {
                return;
            }

            Oltp.AccountRow account = (sender as CheckBox).DataContext as Oltp.AccountRow;
            _relatedAccountsTable.FindByAccountIDRelatedAccountID(Window.CurrentAccount.ID, account.ID).Delete();
        }
Пример #6
0
        public bool HasPermission(Oltp.AccountRow account, XmlElement pageData)
        {
            if (OltpProxy.CurrentUser.AccountAdmin)
            {
                return(true);
            }

            string permissionName = pageData.HasAttribute("Permission") ?
                                    pageData.Attributes["Permission"].Value :
                                    pageData.Attributes["Class"].Value;

            string condition = account != null?
                               String.Format("AccountID = {0} and PermissionType = '{1}'", account.ID, permissionName) :
                                   String.Format("PermissionType = '{0}'", permissionName);

            return(_userPermissions.Select(condition).Length > 0);
        }
Пример #7
0
        public override void OnAccountChanged()
        {
            Oltp.AccountRow currentAccount = Window.CurrentAccount;

            string lurl;

            if (!this.PageData.HasAttribute("Url"))
            {
                lurl = "about:No URL defined for this page.";
            }
            else
            {
                string pageUrl = this.PageData.GetAttribute("Url");
                lurl =
                    (RootAddress != null && !pageUrl.Contains("://") ? RootAddress : null) +
                    ExpandSymbols(this.PageData.GetAttribute("Url"));
            }

            Browser.Navigate(new Uri(lurl));
        }
Пример #8
0
        /*=========================*/
        #endregion

        #region Internal methods
        /*=========================*/
        /// <summary>
        ///
        /// </summary>
        private void _accountsSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count < 1)
            {
                return;
            }

            // Get the selected account
            Oltp.AccountRow accountToChangeTo = (e.AddedItems[0] as DataRowView).Row as Oltp.AccountRow;

            if (CurrentPage != null && !CurrentPage.OnAccountChanging(accountToChangeTo))
            {
                // Cancel the change (disable the event)
                _accountsSelector.SelectionChanged -= _accountsSelector_SelectionChangedHandler;
                _accountsSelector.SelectedItem      = CurrentAccount;
                _accountsSelector.SelectionChanged += _accountsSelector_SelectionChangedHandler;
            }

            // Disable unavialable menu items for this account
            _mainMenu.ApplyPermissions(accountToChangeTo);

            if (CurrentPage != null && !HasPermission(accountToChangeTo, CurrentPage.PageData))
            {
                // Hide page if the current page is not enabled
                HidePageContents(HideContentsReason.AccessDenied);
            }
            else
            {
                // Complete the change
                CurrentAccount = accountToChangeTo;

                string selectedAccountCookie = String.Format("{0}.SelectedAccount", OltpProxy.CurrentUser.ID);
                App.Cookies[selectedAccountCookie] = accountToChangeTo.ID.ToString();
            }

            if (CurrentPage != null)
            {
                RestorePageContents();
                CurrentPage.OnAccountChanged();
            }
        }
Пример #9
0
            public override DataTemplate SelectTemplate(object item, DependencyObject container)
            {
                if (item is DataRowView && ((DataRowView)item).Row is Oltp.AccountRow)
                {
                    Oltp.AccountRow accountRow = (Oltp.AccountRow)((DataRowView)item).Row;
                    string          template   =
                        accountRow.ID == accountRow.ClientID ?
                        "AccountItem_AccountTopLevel_{0}" :
                        "AccountItem_AccountSubLevel_{0}";

                    template = String.Format(template,
                                             !OltpProxy.CurrentUser.IsAccountAdminNull() && OltpProxy.CurrentUser.AccountAdmin ?
                                             "Admin" :
                                             "Normal");

                    return(MainWindow.Current
                           .FindResource(template) as DataTemplate);
                }
                else
                {
                    return(null);
                }
            }
Пример #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="include"></param>
        private void GetCreatives(Oltp.AccountRow account, string filter, bool include)
        {
            Oltp.AccountRow currentAccount = account == null ? this.Window.CurrentAccount : account;

            if (currentAccount == null)
            {
                return;
            }

            Window.AsyncOperation(delegate()
            {
                using (OltpProxy proxy = new OltpProxy())
                {
                    _creatives = proxy.Service.Creative_Get(currentAccount.ID, filter, include);
                }
            },
                                  delegate()
            {
                // Get an empty new list
                if (_items == null)
                {
                    _items = new ObservableCollection <DataRow>();
                }
                else
                {
                    _items.Clear();
                }

                // Add all items
                foreach (DataRow r in _creatives.Rows)
                {
                    _items.Add(r);
                }

                _listTable.ListView.ItemsSource = _items;
            });
        }
 /// <summary>
 /// Called when the selected client account is being changed.
 /// </summary>
 /// <returns>True to continue, false to cancel.</returns>
 public virtual bool OnAccountChanging(Oltp.AccountRow account)
 {
     return(true);
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="include"></param>
        private void GetPermissionTargets(Oltp.AccountRow account)
        {
            Oltp.AccountRow currentAccount = account == null ? this.Window.CurrentAccount : account;

            if (currentAccount == null)
            {
                return;
            }

            Oltp.UserGroupDataTable groupsWith    = null;
            Oltp.UserDataTable      usersWith     = null;
            Oltp.UserGroupDataTable groupsWithout = null;
            Oltp.UserDataTable      usersWithout  = null;

            // Set to null if we need to retrieve it from db
            _copyToAccounts = Window.CurrentUser.AccountAdmin ?
                              Window.AvailableAccounts :
                              null;

            Window.AsyncOperation(delegate()
            {
                using (OltpProxy proxy = new OltpProxy())
                {
                    groupsWith    = proxy.Service.UserGroup_GetGroupsWithPermissions(currentAccount.ID);
                    usersWith     = proxy.Service.User_GetUsersWithPermissions(currentAccount.ID);
                    groupsWithout = proxy.Service.UserGroup_GetGroupsWithoutPermissions(currentAccount.ID);
                    usersWithout  = proxy.Service.User_GetUsersWithoutPermissions(currentAccount.ID);

                    _copyToAccounts =
                        // If not null
                        _copyToAccounts
                        ??
                        // else
                        proxy.Service.Account_GetByPermission(this.PageData.Path);
                }
            },
                                  delegate()
            {
                // Get an empty new list
                if (_items == null)
                {
                    _items = new ObservableCollection <DataRow>();
                }
                else
                {
                    _items.Clear();
                }

                // Add all items
                foreach (DataRow r in groupsWith.Rows)
                {
                    _items.Add(r);
                }
                foreach (DataRow r in usersWith.Rows)
                {
                    _items.Add(r);
                }

                _listTable.ListView.ItemsSource = _items;

                //-------------------------------//

                // Populate 'add' combo boxes
                if (_groupsToAdd == null)
                {
                    _groupsToAdd = new ObservableCollection <object>();
                }
                else
                {
                    _groupsToAdd.Clear();
                }

                if (_usersToAdd == null)
                {
                    _usersToAdd = new ObservableCollection <object>();
                }
                else
                {
                    _usersToAdd.Clear();
                }

                _groupsToAdd.Add("Add group");
                _usersToAdd.Add("Add user");

                foreach (DataRow r in groupsWithout.Rows)
                {
                    _groupsToAdd.Add(r);
                }
                foreach (DataRow r in usersWithout.Rows)
                {
                    _usersToAdd.Add(r);
                }

                _comboAddGroup.ItemsSource = _groupsToAdd;
                _comboAddUser.ItemsSource  = _usersToAdd;

                _comboAddGroup.SelectedIndex = 0;
                _comboAddUser.SelectedIndex  = 0;

                if (_copyToAccountsListBox != null)
                {
                    _copyToAccountsListBox.DataContext = Filter(_copyToAccounts);
                }
            });
        }
Пример #13
0
        /// <summary>
        ///
        /// </summary>
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Version v = ApplicationDeployment.IsNetworkDeployed ?
                        ApplicationDeployment.CurrentDeployment.CurrentVersion :
                        Assembly.GetExecutingAssembly().GetName().Version;

            //Version v = Assembly.GetExecutingAssembly().GetName().Version;
            _version.Content = "Version " + v.ToString();

            // Settings we should get from the deployment URL
            int    accountID;
            string menuItemPath;
            string sessionID;

                        #if DEBUG
            accountID    = 1240244;
            sessionID    = "4F873C89AEE75E485893C7AE16E09020";
            menuItemPath = "management/trackers";
                        #endif

            // Normal producion
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                if (ApplicationDeployment.CurrentDeployment.ActivationUri.Query == null)
                {
                    HidePageContents("This page must be accessed via the Edge.BI interface.");
                    return;
                }

                NameValueCollection urlParams =
                    HttpUtility.ParseQueryString(ApplicationDeployment.CurrentDeployment.ActivationUri.Query);

                // Invalid account
                string accountIDParam = urlParams["account"];
                if (accountIDParam == null || !Int32.TryParse(accountIDParam, out accountID))
                {
                    HidePageContents("Invalid account specified. Please select another account.");
                    return;
                }

                // Log in from session param
                sessionID = urlParams["session"];
                if (String.IsNullOrEmpty(sessionID))
                {
                    HidePageContents("Invalid session specified. Try logging out and logging back in.");
                    return;
                }

                menuItemPath = urlParams["path"];
                if (String.IsNullOrEmpty(menuItemPath))
                {
                    HidePageContents("Invalid menu path specified. Please select an item from the menu.");
                    return;
                }
            }
            else
            {
                                #if !DEBUG
                {
                    HidePageContents("This page must be accessed via the Edge.BI interface.");
                    return;
                }
                                #endif
            }

            ApiMenuItem menuItem = null;

            // Get user settings
            AsyncOperation(delegate()
            {
                OltpProxy.SessionStart(sessionID);
                using (OltpProxy proxy = new OltpProxy())
                {
                    _accountsTable   = proxy.Service.Account_Get();
                    _userPermissions = proxy.Service.User_GetAllPermissions();
                    menuItem         = proxy.Service.ApiMenuItem_GetByPath(menuItemPath);
                }
            },
                           delegate(Exception ex)
            {
                HidePageContents(null, ex);
                return(false);
            },
                           delegate()
            {
                CurrentUser  = OltpProxy.CurrentUser;
                DataRow[] rs = _accountsTable.Select("ID = " + accountID.ToString());
                if (rs.Length < 1)
                {
                    HidePageContents("Specified account was not found. Please select another account.");
                    return;
                }

                _currentAccount = (Oltp.AccountRow)rs[0];
                LoadPage(menuItem);
            });
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="include"></param>
        private void GetPermissionTargets(Oltp.AccountRow account)
        {
            Oltp.AccountRow currentAccount = account == null ? this.Window.CurrentAccount : account;

            if (currentAccount == null)
            {
                return;
            }

            Oltp.UserGroupDataTable groupsWith    = null;
            Oltp.UserDataTable      usersWith     = null;
            Oltp.UserGroupDataTable groupsWithout = null;
            Oltp.UserDataTable      usersWithout  = null;

            Window.AsyncOperation(delegate()
            {
                using (OltpProxy proxy = new OltpProxy())
                {
                    groupsWith    = proxy.Service.UserGroup_GetGroupsWithPermissions(currentAccount.ID);
                    usersWith     = proxy.Service.User_GetUsersWithPermissions(currentAccount.ID);
                    groupsWithout = proxy.Service.UserGroup_GetGroupsWithoutPermissions(currentAccount.ID);
                    usersWithout  = proxy.Service.User_GetUsersWithoutPermissions(currentAccount.ID);
                }
            },
                                  delegate()
            {
                // Get an empty new list
                if (_items == null)
                {
                    _items = new ObservableCollection <DataRow>();
                }
                else
                {
                    _items.Clear();
                }

                // Add all items
                foreach (DataRow r in groupsWith.Rows)
                {
                    _items.Add(r);
                }
                foreach (DataRow r in usersWith.Rows)
                {
                    _items.Add(r);
                }

                _listTable.ListView.ItemsSource = _items;

                //-------------------------------//

                // Populate 'add' combo boxes
                if (_groupsToAdd == null)
                {
                    _groupsToAdd = new ObservableCollection <object>();
                }
                else
                {
                    _groupsToAdd.Clear();
                }

                if (_usersToAdd == null)
                {
                    _usersToAdd = new ObservableCollection <object>();
                }
                else
                {
                    _usersToAdd.Clear();
                }

                _groupsToAdd.Add("Add group");
                _usersToAdd.Add("Add user");

                foreach (DataRow r in groupsWithout.Rows)
                {
                    _groupsToAdd.Add(r);
                }
                foreach (DataRow r in usersWithout.Rows)
                {
                    _usersToAdd.Add(r);
                }

                _comboAddGroup.ItemsSource = _groupsToAdd;
                _comboAddUser.ItemsSource  = _usersToAdd;

                _comboAddGroup.SelectedIndex = 0;
                _comboAddUser.SelectedIndex  = 0;;
            });
        }