Example #1
0
        /// <summary>
        /// Update the debt class with new information from another debt class.
        /// </summary>
        /// <param name="entity"></param>
        public override void Update(GuardianObject entity)
        {
            DebtClass source = entity as DebtClass;

            if (!this.Modified && this.DebtClassId == source.DebtClassId)
            {
                this.DebtRuleId = source.DebtRuleId;

                this.Address1          = source.Address1;
                this.Address2          = source.Address2;
                this.BankRoutingNumber = source.BankRoutingNumber;
                this.BankAccountNumber = source.BankAccountNumber;
                this.City               = source.City;
                this.CompanyName        = source.CompanyName;
                this.ContactName        = source.ContactName;
                this.Department         = source.Department;
                this.Email              = source.Email;
                this.Fax                = source.Fax;
                this.ForBenefitOf       = source.ForBenefitOf;
                this.Phone              = source.Phone;
                this.Province           = source.Province;
                this.PostalCode         = source.PostalCode;
                this.SettlementTemplate = source.SettlementTemplate;
                this.Modified           = false;
            }

            this.rowVersion = source.RowVersion;
        }
        /// <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);
        }
Example #4
0
        /// <summary>
        /// Find the effective (inherited) value of a column in a debt class.
        /// </summary>
        /// <typeparam name="T">The type of the column.</typeparam>
        /// <param name="debtClassId">The DebtClassId of the debt class in question.</param>
        /// <param name="field">The column to retrieve.</param>
        /// <returns>Effective value of the indicated column, eg. the value in the debt class with the indicated ID, or, if that debt class has no
        /// value for the column, the value of the column in nearest ancestor debt class that has a value for that column. If no value can be found,
        /// returns null.</returns>
        private static object FindEffectiveField <T>(Guid debtClassId, DataColumn field)
        {
            object value = null;

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

                if (parent != null)
                {
                    value = (object)parent.Field <T>(field);
                }
            }

            return(value);
        }
Example #5
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.
            }
        }
Example #7
0
 /// <summary>
 /// Get the effective (inherited) value of PostalCode.
 /// </summary>
 /// <returns>If PostalCode is non-null, returns PostalCode, otherwise returns the PostalCode of the closest ancestor whose PostalCode is non-null.</returns>
 public string GetEffectivePostalCode()
 {
     return(DebtClass.FindEffectiveField <string>(this.DebtClassId, DataModel.DebtClass.PostalCodeColumn) as string);
 }
Example #8
0
 /// <summary>
 /// Get the effective (inherited) value of State.
 /// </summary>
 /// <returns>If State is non-null, returns State, otherwise returns the State of the closest ancestor whose State is non-null.</returns>
 public string GetEffectiveState()
 {
     return(DebtClass.FindEffectiveField <string>(this.DebtClassId, DataModel.DebtClass.ProvinceIdColumn) as string);
 }
Example #9
0
 /// <summary>
 /// Get the effective (inherited) value of ForBenefitOf.
 /// </summary>
 /// <returns>If ForBenefitOf is non-null, returns ForBenefitOf, otherwise returns the ForBenefitOf of the closest ancestor whose ForBenefitOf
 /// is non-null.</returns>
 public string GetEffectiveForBenefitOf()
 {
     return(DebtClass.FindEffectiveField <string>(this.DebtClassId, DataModel.DebtClass.ForBenefitOfColumn) as string);
 }
Example #10
0
 /// <summary>
 /// Get the effective (inherited) value of Email.
 /// </summary>
 /// <returns>If Email is non-null, returns Email, otherwise returns the Email of the closest ancestor whose Email is non-null.</returns>
 public string GetEffectiveEmail()
 {
     return(DebtClass.FindEffectiveField <string>(this.DebtClassId, DataModel.DebtClass.EmailColumn) as string);
 }
Example #11
0
 /// <summary>
 /// Get the effective (inherited) value of Department.
 /// </summary>
 /// <returns>If Department is non-null, returns Department, otherwise returns the Department of the closest ancestor whose Department is
 /// non-null.</returns>
 public string GetEffectiveDepartment()
 {
     return(DebtClass.FindEffectiveField <string>(this.DebtClassId, DataModel.DebtClass.DepartmentColumn) as string);
 }
Example #12
0
 /// <summary>
 /// Get the effective (inherited) value of ContactName.
 /// </summary>
 /// <returns>If ContactName is non-null, returns ContactName, otherwise returns the ContactName of the closest ancestor whose ContactName is
 /// non-null.</returns>
 public string GetEffectiveContactName()
 {
     return(DebtClass.FindEffectiveField <string>(this.DebtClassId, DataModel.DebtClass.ContactNameColumn) as string);
 }
Example #13
0
 /// <summary>
 /// Get the effective (inherited) value of BankRoutingNumber.
 /// </summary>
 /// <returns>If BankRoutingNumber is non-null, returns BankRoutingNumber, otherwise returns the BankRoutingNumber of the closest ancestor
 /// whose BankRoutingNumber is non-null.</returns>
 public string GetEffectiveBankRoutingNumber()
 {
     return(DebtClass.FindEffectiveField <string>(this.DebtClassId, DataModel.DebtClass.BankRoutingNumberColumn) as string);
 }
Example #14
0
 /// <summary>
 /// Get the effective (inherited) value of Address2.
 /// </summary>
 /// <returns>If Address2 is non-null, returns Address2, otherwise returns the Address2 of the closest ancestor whose Address2 is
 /// non-null.</returns>
 public string GetEffectiveAddress2()
 {
     return(DebtClass.FindEffectiveField <string>(this.DebtClassId, DataModel.DebtClass.Address2Column) as string);
 }
Example #15
0
 /// <summary>
 /// Get the debt rule used for this debt class. This function locks the DataModel.
 /// </summary>
 /// <returns>The debt rule. If none can be found either in the debt class or its ancestors, null is returned.</returns>
 public DebtRule GetDebtRule()
 {
     return(DebtClass.GetDebtRule(this.EntityId, this.TypeId));
 }
Example #16
0
 /// <summary>
 /// Create a duplicate debt class.
 /// </summary>
 /// <param name="source">The original debt class.</param>
 public DebtClass(DebtClass source) : base(source)
 {
     this.Update(source);
 }