Пример #1
0
        /// <summary>
        /// Close the window and reset the cursor. If data is not null, it is an exception that occured in the background that the user should be
        /// alerted to. In this case, the window will not be closed so the user may try again.
        /// </summary>
        /// <param name="rule">The rule that triggered the exception (if any).</param>
        /// <param name="exception">Any exception that should be brought to the user's attention.</param>
        private void BackgroundClose(DebtRule rule, Exception exception)
        {
            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate()
            {
                if (exception != null)
                {
                    if (exception is DebtRuleInUseException)
                    {
                        MessageBox.Show(
                            this,
                            String.Format(Properties.Resources.DeleteFailedDebtRuleInUse, rule.Name),
                            this.Title);
                    }
                    else if (exception is SecurityAccessDeniedException)
                    {
                        MessageBox.Show(
                            this,
                            String.Format(Properties.Resources.DeleteFailedAccessDenied, rule.Name),
                            this.Title);
                    }
                    else
                    {
                        MessageBox.Show(this, Properties.Resources.OperationFailed, this.Title);
                    }
                }
                else
                {
                    this.Close();
                }

                this.Cursor = Cursors.Arrow;
            }));
        }
        /// <summary>
        /// Populate the drop-down list of rules and the debt rule display. If possible, keep the selection.
        /// </summary>
        /// <param name="enabled">Whether the window is enabled.</param>
        /// <param name="rules">The rules to populate the drop-down with.</param>
        /// <param name="currentRule">The currently selected rule.</param>
        /// <param name="inherited">Whether the selected debt rule is inherited from a parent entity.</param>
        private void Populate(Boolean enabled, List <DebtRule> rules, DebtRule currentRule, Boolean inherited)
        {
            DebtRule oldRule = this.debtRule.SelectedItem as DebtRule;

            this.Populating = true;

            if (enabled)
            {
                this.debtRule.ItemsSource = rules;

                if (oldRule != null && rules.Contains(oldRule))
                {
                    this.debtRule.SelectedItem  = null;
                    this.debtRule.SelectedValue = oldRule.DebtRuleId;
                }
                else if (inherited)
                {
                    this.debtRule.SelectedItem  = null;
                    this.debtRule.SelectedIndex = 0;
                }
                else if (currentRule != null)
                {
                    this.debtRule.SelectedItem = null;
                    this.debtRule.SelectedItem = currentRule;
                }
            }

            this.Populating = false;
        }
        /// <summary>
        /// Populate the debt rule information in the debt rule tab.
        /// </summary>
        protected override void Populate(Entity entity)
        {
            base.Populate(entity);

            try
            {
                lock (DataModel.SyncRoot)
                {
                    DebtClass       debtClass   = entity as DebtClass;
                    List <DebtRule> rules       = null;
                    DebtRule        currentRule = null;
                    Boolean         enabled     = true;
                    Boolean         inherited   = true;

                    // Only populate the window if the entity still exists. (If it doesn't, it's been deleted since the window was opened.)
                    if (entity != null)
                    {
                        rules       = GetAvailableRules(entity);
                        currentRule = debtClass.GetDebtRule();
                        inherited   = debtClass.DebtRuleId == null;
                    }
                    else
                    {
                        enabled = false;
                    }

                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new populate(this.Populate), enabled, rules, currentRule, inherited);
                }
            }
            catch
            {
            }
        }
        /// <summary>
        /// Get a list of the rules available to this debt class.
        /// </summary>
        /// <returns>A list of the available rules.</returns>
        private List <DebtRule> GetAvailableRules(Entity entity)
        {
            List <DebtRule> rules     = new List <DebtRule>();
            DebtClassRow    debtClass = DataModel.DebtClass.DebtClassKey.Find(entity.EntityId);
            DebtClassRow    parent    = this.RetrieveParent(entity.EntityId);

            if (parent != null)
            {
                DebtRule inherited = DebtClass.GetDebtRule(parent.DebtClassId, entity.TypeId);

                inherited.Name       = "<inherit from parent>";
                inherited.DebtRuleId = null;
                rules.Add(inherited);
            }

            while (debtClass != null)
            {
                var maps = DataModel.DebtRuleMap.Where(row => row.DebtClassId == debtClass.DebtClassId);

                foreach (DebtRuleMapRow map in maps)
                {
                    if (map.DebtRuleRow.Name != "")
                    {
                        rules.Add(new DebtRule(map.DebtRuleRow));
                    }
                }

                debtClass = this.RetrieveParent(debtClass.DebtClassId);
            }

            return(rules);
        }
Пример #5
0
        /// <summary>
        /// Update rules that have been modified, destroy rules that have been deleted, and create rules that have been created.
        /// </summary>
        /// <paraparam name="finish">The method to invoke committing is finished.</paraparam>
        /// <paraparam name="rules">The list of rules to commit.</paraparam>
        private void Apply(finishApply finish, DebtRule[] rules)
        {
            Exception exception   = null;
            DebtRule  currentRule = null;

            // We may change some debt rules here, so we need to set populating. Otherwise, changing a DebtRule will raise a property changed event,
            // triggering a change in the CanApply state, which is owned by another thread.
            this.populating = true;

            try
            {
                foreach (DebtRule rule in rules)
                {
                    if (rule.Modified || rule.Delete)
                    {
                        currentRule = rule;

                        if (rule.DebtRuleId != null)
                        {
                            Guid   ruleOwner = Guid.Empty;
                            String oldName   = null;

                            lock (DataModel.SyncRoot)
                            {
                                ruleOwner = this.GetRuleOwner(rule.DebtRuleId.Value);
                                oldName   = DataModel.DebtRule.DebtRuleKey.Find(rule.DebtRuleId.Value).Name;
                            }

                            if (ruleOwner != this.Entity.EntityId)
                            {
                                rule.DebtRuleId = null;

                                if (oldName.Equals(rule.Name))
                                {
                                    rule.Name += " - Copy";
                                }
                            }
                        }

                        // If we're committing a rule, we have to own it. If, in the future, we're able to edit the rules of our children, this
                        // decision will need to get more sophisticated.
                        rule.Commit(this.Entity.EntityId);
                    }
                }

                currentRule = null;
            }
            catch (Exception e)
            {
                exception = e;
            }

            this.populating = false;

            finish(currentRule, exception);
        }
Пример #6
0
        /// <summary>
        /// Handle the create button being clicked. Add a new DebtRule to the rules combobox.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnNew(object sender, EventArgs e)
        {
            DebtRule rule = new DebtRule()
            {
                Name = "New Debt Rule"
            };

            this.rules.Items.Add(rule);
            this.DebtRule = rule;
            this.CanApply = true;
        }
Пример #7
0
        /// <summary>
        /// Handling the apply button being clicked.
        /// </summary>
        /// <param name="sender">The apply button.</param>
        /// <param name="e">The event arguments.</param>
        private void OnApply(object sender, RoutedEventArgs e)
        {
            if (this.CanApply)
            {
                DebtRule[] rules = new DebtRule[this.rules.Items.Count];

                this.Cursor = Cursors.Wait;
                this.rules.Items.CopyTo(rules, 0);

                FluidTrade.Core.ThreadPoolHelper.QueueUserWorkItem(data => this.Apply(new finishApply(this.BackgroundEnable), rules));
            }
        }
Пример #8
0
        /// <summary>
        /// Find the debt rule assocatiated with a debt class of a particular type. This function locks the DataModel.
        /// </summary>
        /// <param name="debtClassId">The DebtClassId of the debt class.</param>
        /// <param name="typeId">The TypeId of the debt class.</param>
        /// <returns>The debt rule. If none can be found either in the debt class or its ancestors, null is returned.</returns>
        public static DebtRule GetDebtRule(Guid debtClassId, Guid typeId)
        {
            DebtRule rule = null;

            lock (DataModel.SyncRoot)
            {
                DebtClassRow parent = DebtClass.FindParentWithField(debtClassId, DataModel.DebtClass.DebtRuleIdColumn);

                if (parent != null)
                {
                    rule = new DebtRule(parent.DebtRuleRow);
                }
            }

            return(rule);
        }
        /// <summary>
        /// Background thread that initializes the status bar.
        /// </summary>
        protected override void Populate()
        {
            // Make sure the common properties are updated before addressing the extended properties.
            base.Populate();

            try
            {
                Boolean  entityDeleted  = false;
                decimal  matchedDollars = 0m;
                decimal  totalDollars   = 0m;
                int      totalRecords   = 0;
                int      matchedRecords = 0;
                Guid     blotterId      = this.entityId;
                DebtRule rule           = null;

                lock (DataModel.SyncRoot)
                {
                    EntityRow entityRow = DataModel.Entity.EntityKey.Find(blotterId);

                    if (entityRow != null)
                    {
                        CountChildMoney(entityRow, ref matchedDollars, ref totalDollars, ref totalRecords, ref matchedRecords);
                        rule = DebtClass.GetDebtRule(this.entityId, entityRow.TypeId);
                    }
                    else
                    {
                        entityDeleted = true;
                    }
                }

                if (!entityDeleted && rule != null)
                {
                    this.Dispatcher.BeginInvoke(
                        DispatcherPriority.Normal,
                        new SetStatusBarDelegate(Populate),
                        Decimal.ToDouble(matchedDollars),
                        Decimal.ToDouble(totalDollars),
                        Decimal.ToDouble(rule.SettlementValue),
                        totalRecords,
                        matchedRecords);
                }
            }
            catch
            {
                // If we fail, we'll just keep up the old status bar.
            }
        }
Пример #10
0
        /// <summary>
        /// Populate the rules drop-down with a list of rules.
        /// </summary>
        /// <param name="rules">The list of rules.</param>
        void PopulateRules(List <DebtRule> rules)
        {
            DebtRule selected    = this.DebtRule;
            DebtRule newSelected = null;
            Int64    oldVersion  = selected == null ? 0 : selected.RowVersion;

            this.populating = true;

            for (int index = 0; index < this.rules.Items.Count; index += 1)
            {
                DebtRule rule = this.rules.Items[index] as DebtRule;

                if (rules.Contains(rule))
                {
                    if (rule.Equals(selected))
                    {
                        newSelected = rule;
                    }
                    rule.Update(rules.FirstOrDefault((r) => r.Equals(rule)));
                    rules.Remove(rule);
                }
                else if (!rule.New)
                {
                    this.rules.Items.Remove(rule);
                    index -= 1;
                }
            }
            foreach (DebtRule rule in rules)
            {
                this.rules.Items.Add(rule);
            }

            if (selected == null || !this.rules.Items.Contains(selected))
            {
                this.rules.SelectedItem  = null;
                this.rules.SelectedIndex = 0;
            }
            else if (newSelected != null && oldVersion != newSelected.RowVersion)
            {
                this.rules.SelectedItem  = null;
                this.rules.SelectedValue = selected.DebtRuleId;
            }

            this.populating = false;
        }