コード例 #1
0
        /*
         * ///<summary>
         * ///Gets the default contact.
         * /// </summary>
         * /// <value>The default contact.</value>
         * public Contact DefaultContact
         * {
         *  get
         *  {
         *      if (Contacts == null)
         *      {
         *          return null;
         *      }
         *      return Contacts.Where(x => x.IsDefault).FirstOrDefault();
         *  }
         * }
         *
         * ///<summary>
         * /// Adds the contact.
         * /// </summary>
         * /// <param name="contact">The contact.</param>
         * public void AddContact(Contact contact)
         * {
         *  if (Contacts == null)
         *  {
         *      Contacts = new List<Contact>();
         *  }
         *
         *  // If there are not default address, set this one as default
         *  if (Contacts.Where(x => x.IsDefault).Count() < 1)
         *  {
         *      contact.IsDefault = true;
         *  }
         *
         *  // If this is the new default address
         *  if (contact.IsDefault)
         *  {
         *      foreach (Contact cont in Contacts)
         *      {
         *          cont.IsDefault = false;
         *      }
         *  }
         *
         *  // If the address is not already in the list
         *  if (!Contacts.Any(x => x.PrimaryKey == contact.PrimaryKey))
         *  {
         *      Contacts.Add(contact);
         *      contact.Company = this;
         *  }
         * }
         *
         * ///<summary>
         * /// Removes the contact.
         * /// </summary>
         * /// <param name="contact">The contact.</param>
         * public void RemoveContact(Contact contact)
         * {
         *  if (Contacts == null)
         *  {
         *      return;
         *  }
         *
         *  Contacts.Remove(contact);
         *
         *  if (contact.IsDefault)
         *  {
         *      Contacts.FirstOrDefault().IsDefault = true;
         *  }
         * }
         *
         * ///<summary>
         * ///Gets the default address.
         * /// </summary>
         * /// <value>The default address.</value>
         * public Address DefaultAddress
         * {
         *  get
         *  {
         *      if (Addresses == null)
         *      {
         *          return null;
         *      }
         *      return Addresses.Where(x => x.IsDefault).FirstOrDefault();
         *  }
         * }
         *
         * ///<summary>
         * /// Adds the address.
         * /// </summary>
         * /// <param name="contact">The address.</param>
         * public void AddAddress(Address address)
         * {
         *  if (Addresses == null)
         *  {
         *      Addresses = new List<Address>();
         *  }
         *
         *  // If there are not default address, set this one as default
         *  if (Addresses.Where(x => x.IsDefault).Count() < 1)
         *  {
         *      address.IsDefault = true;
         *  }
         *
         *  // If this is the new default address
         *  if (address.IsDefault)
         *  {
         *      foreach (Address addr in Addresses)
         *      {
         *          addr.IsDefault = false;
         *      }
         *  }
         *
         *  // If the address is not already in the list
         *  if (!Addresses.Any(x => x.PrimaryKey == address.PrimaryKey))
         *  {
         *      Addresses.Add(address);
         *      address.Company = this;
         *  }
         * }
         *
         * ///<summary>
         * /// Removes the address.
         * /// </summary>
         * /// <param name="contact">The address.</param>
         * public void RemoveAddress(Address address)
         * {
         *  if (Addresses == null)
         *  {
         *      return;
         *  }
         *
         *  Addresses.Remove(address);
         *
         *  if (address.IsDefault)
         *  {
         *      Addresses.FirstOrDefault().IsDefault = true;
         *  }
         * }
         */
        ///<summary>
        /// Adds the financial year.
        /// </summary>
        /// <param name="year">The financial year.</param>
        public void AddFinancialYear(FinancialYear fnYear)
        {
            if (FinancialYears == null)
            {
                FinancialYears = new List <FinancialYear>();
            }

            // If there are not default year, set this one as default
            if (FinancialYears.Where(x => x.IsDefault).Count() < 1)
            {
                fnYear.IsDefault = true;
            }

            // If this is the new default year
            if (fnYear.IsDefault)
            {
                foreach (FinancialYear fy in FinancialYears)
                {
                    fy.IsDefault = false;
                }
            }

            // If the year is not already in the list
            if (!FinancialYears.Any(x => x.PrimaryKey == fnYear.PrimaryKey))
            {
                FinancialYears.Add(fnYear);
                fnYear.Company = this;
            }
        }
コード例 #2
0
        ///<summary>
        /// Removes the financial year.
        /// </summary>
        /// <param name="year">The year.</param>
        public void RemoveFinancialYear(FinancialYear fnYear)
        {
            if (FinancialYears == null)
            {
                return;
            }

            FinancialYears.Remove(fnYear);

            if (fnYear.IsDefault)
            {
                FinancialYears.FirstOrDefault().IsDefault = true;
            }
        }
コード例 #3
0
        private void PopulateFinancialYearList()
        {
            // Determinefirst and last financial years
            var currentFinancialYear = Date.Today.FinancialYear();
            var oldestFinancialYear  = PortfolioDateRange.FromDate.FinancialYear();

            if (FinancialYears.Count == 0)
            {
                FinancialYears.Add(new DescribedObject <int>(currentFinancialYear, "Current"));
                FinancialYears.Add(new DescribedObject <int>(currentFinancialYear - 1, "Previous"));

                ViewParameter.FinancialYear = currentFinancialYear;

                return;
            }

            if (PortfolioDateRange.FromDate == Date.MinValue)
            {
                return;
            }

            var lastYearInList = FinancialYears.Last().Value;

            if (lastYearInList > oldestFinancialYear)
            {
                var year = lastYearInList - 1;
                while (year > oldestFinancialYear)
                {
                    FinancialYears.Add(new DescribedObject <int>(year, String.Format("{0} - {1}", year - 1, year)));
                    year--;
                }
            }
            else if (lastYearInList < oldestFinancialYear)
            {
                var year = lastYearInList;
                while (year > oldestFinancialYear)
                {
                    FinancialYears.RemoveAt(FinancialYears.Count - 1);
                    year++;
                }
            }
        }