コード例 #1
0
		private void Run(JulianDay startDate, JulianDay endDate, BackgroundWorker worker, DoWorkEventArgs e)
		{
			JulianDay profileStartDate = App.Model.ProfileHolder.Profile.StartProfileDate.JulianDay;
			JulianDay profileEndDate = App.Model.ProfileHolder.Profile.EndProfileDate.JulianDay;
			// profileStartDate and profileEndDate could be 0

			if (startDate == 0 && endDate == 0)
			{
				startDate = profileStartDate;
				endDate = profileEndDate;
			}

			// Clip the passed start date to the document start date
			if (startDate < profileStartDate)
				startDate = profileStartDate;

			// Always run to the end of the document since changes ripple to the end
			endDate = profileEndDate;

			// From the start date forward, truncate the daily balances
			// Don't leave before doing this!
			_Accounts.TruncateBalance(startDate);
			_Categories.TruncateBalance(startDate);

			// If Dates were never set or nothing to do
			if ((profileStartDate == 0 && profileEndDate == 0) || startDate > profileEndDate)
			{
				UpdateBalances(worker, e);
				return;
			}
#if NOTUSED
			Helper.Trace("Calculating account values between {0,2:d2}/{1,2:d2}/{2,2:d2} and {3,2:d2}/{4,2:d2}/{5,2:d2}",
				startDate.Month(), startDate.Day(), startDate.Year(), endDate.Month(), endDate.Day(), endDate.Year());
			DateTime SystemTime = DateTime.Now;
			Helper.Trace("Start: {0,2:d2}:{1,2:d2}:{2,2:d2}:{3,2:d2}", SystemTime.Hour, SystemTime.Minute, SystemTime.Second, SystemTime.Millisecond);
#endif
			// Let the packages know we are about to run
			IncomeBalances.Clear();
			SpendingBalances.Clear();
			_Incomes.RunPrepare(this);
			_Packages.RunPrepare(this);

			// Loop thru all the dates in the running date range
			for (JulianDay date = startDate; date <= endDate; date++)
			{
				if (worker != null && worker.CancellationPending)
				{
					e.Cancel = true;
					return;
				}

				// Run the packages for the given date
				_Incomes.Run(this, date);
				_Packages.Run(this, date);

				// At the end of each day, handle any negative account balances by putting them on the credit account
				_Accounts.BorrowFromCredit(this, date);

				// At the end of each month, make credit payments if needed
				JulianDay tomorrow = date + 1;
				bool bMonthlyRun = (tomorrow.Day() == 1);
				if (bMonthlyRun)
					_Accounts.PayoffCredit(this, date);
			}

			// Update the RunCount for anyone listening
			RunCount++;

			UpdateBalances(worker, e);
#if NOTUSED
			SystemTime = DateTime.Now;
			Helper.Trace("End: {0,2:d2}:{1,2:d2}:{2,2:d2}:{3,2:d2}", SystemTime.Hour, SystemTime.Minute, SystemTime.Second, SystemTime.Millisecond);
#endif
		}