示例#1
0
 /// <summary>
 /// Initialises from a given context.
 /// </summary>
 /// <param name="context">Context.</param>
 public void InitialiseFrom(LoanContext context)
 {
     LoanStartDateField.text = context.StartDate.ToShortDateString ();
     if(context.TargetEndDate != DateTime.MinValue) LoanTargetEndDateField.text = context.TargetEndDate.ToShortDateString ();
     LoanBalanceField.text = context.Balance.ToString ();
     LoanInterestRateField.text = context.InterestRate.ToString ();
     LoanMinRepaymentDayField.text = context.MinRepaymentDay.ToString ();
     LoanMinRepaymentAmountField.text = context.MinRepaymentAmount.ToString ();
     LoanExtraRepaymentDayField.text = context.ExtraRepaymentDay.ToString ();
     LoanExtraRepaymentAmountField.text = context.ExtraRepaymentAmount.ToString ();
     navigator.Initialise ();
 }
示例#2
0
 /// <summary>
 /// Awake this instance.
 /// </summary>
 private void Awake()
 {
     CultureInfo enAU = new System.Globalization.CultureInfo ("en-AU");
     Thread.CurrentThread.CurrentCulture = enAU;
     Thread.CurrentThread.CurrentUICulture = enAU;
     defaultState = BuildDefaultLoanContext ();
     applicationSaveStateLock = new object ();
     applicationLoadStateLock = new object ();
     InputPanelController.BuildRequested += HandleBuildRequested;
     TowerBuilder.ClearTower ();
     InputPanelController.ShowInputPanel ();
     TryLoadSavedState ();
 }
示例#3
0
 /// <summary>
 /// Builds the default loan context.
 /// </summary>
 /// <returns>The default loan context.</returns>
 private LoanContext BuildDefaultLoanContext()
 {
     LoanContext result = new LoanContext ();
     result.Balance = 200000.00d;
     result.ExtraRepaymentAmount = 1000.00d;
     result.ExtraRepaymentDay = 18;
     result.InterestRate = 5.50d;
     result.MinRepaymentAmount = 1500.00d;
     result.MinRepaymentDay = 1;
     result.StartDate = DateTime.Now;
     result.TargetEndDate = DateTime.Now.AddYears (8);
     result.TodaysDate = DateTime.Now;
     return(result);
 }
示例#4
0
 /// <summary>
 /// Validates the loan target end date.
 /// </summary>
 /// <param name="context">Context.</param>
 /// <param name="validationResults">Validation results.</param>
 private void ValidateLoanTargetEndDate(LoanContext context, List<bool> validationResults)
 {
     DateTime loanTargetEnd = DateTime.MinValue;
     bool valid = true;
     // allow this field to be empty
     if (!string.IsNullOrEmpty (LoanTargetEndDateField.text)) {
         DateTime.TryParseExact (LoanTargetEndDateField.text, Constants.DateFormatsForParsing, CultureInfo.CurrentCulture, DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeLocal, out loanTargetEnd);
     }
     ProcessFieldValidationColor (valid, LoanTargetEndDateField);
     context.TargetEndDate = loanTargetEnd;
     validationResults.Add (valid);
 }
示例#5
0
 /// <summary>
 /// Validates the loan start date.
 /// </summary>
 /// <param name="context">Context.</param>
 /// <param name="validationResults">Validation results.</param>
 private void ValidateLoanStartDate(LoanContext context, List<bool> validationResults)
 {
     DateTime loanStart = DateTime.Now;
     bool valid = DateTime.TryParseExact (LoanStartDateField.text, Constants.DateFormatsForParsing, CultureInfo.CurrentCulture, DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeLocal, out loanStart);
     ProcessFieldValidationColor (valid, LoanStartDateField);
     context.StartDate = loanStart;
     validationResults.Add (valid);
 }
示例#6
0
 /// <summary>
 /// Validates the loan minimum repayment day.
 /// </summary>
 /// <param name="context">Context.</param>
 /// <param name="validationResults">Validation results.</param>
 private void ValidateLoanMinRepaymentDay(LoanContext context, List<bool> validationResults)
 {
     int minRepaymentDay = 1;
     bool valid = int.TryParse (LoanMinRepaymentDayField.text, NumberStyles.Integer, CultureInfo.CurrentCulture, out minRepaymentDay);
     valid = valid && minRepaymentDay >= 1 && minRepaymentDay <= 31;
     ProcessFieldValidationColor (valid, LoanMinRepaymentDayField);
     context.MinRepaymentDay = minRepaymentDay;
     validationResults.Add (valid);
 }
示例#7
0
 /// <summary>
 /// Validates the loan minimum repayment amount.
 /// </summary>
 /// <param name="context">Context.</param>
 /// <param name="validationResults">Validation results.</param>
 private void ValidateLoanMinRepaymentAmount(LoanContext context, List<bool> validationResults)
 {
     double minRepaymentAmount = 0.0d;
     bool valid = double.TryParse (LoanMinRepaymentAmountField.text, NumberStyles.AllowCurrencySymbol | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.CurrentCulture, out minRepaymentAmount);
     valid = valid && minRepaymentAmount > 0;
     ProcessFieldValidationColor (valid, LoanMinRepaymentAmountField);
     context.MinRepaymentAmount = minRepaymentAmount;
     validationResults.Add (valid);
 }
示例#8
0
 /// <summary>
 /// Validates the loan interest rate.
 /// </summary>
 /// <param name="context">Context.</param>
 /// <param name="validationResults">Validation results.</param>
 private void ValidateLoanInterestRate(LoanContext context, List<bool> validationResults)
 {
     double interestRate = 0.0d;
     bool valid = double.TryParse (LoanInterestRateField.text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.CurrentCulture, out interestRate);
     ProcessFieldValidationColor (valid, LoanInterestRateField);
     context.InterestRate = interestRate;
     validationResults.Add (valid);
 }
示例#9
0
 /// <summary>
 /// Validates the loan extra repayment day.
 /// </summary>
 /// <param name="context">Context.</param>
 /// <param name="validationResults">Validation results.</param>
 private void ValidateLoanExtraRepaymentDay(LoanContext context, List<bool> validationResults)
 {
     int extraRepaymentDay = 1;
     bool valid = true;
     if (!string.IsNullOrEmpty (LoanExtraRepaymentDayField.text)) {
         int.TryParse (LoanExtraRepaymentDayField.text, NumberStyles.Integer, CultureInfo.CurrentCulture, out extraRepaymentDay);
         valid = valid && extraRepaymentDay >= 1 && extraRepaymentDay <= 31;
     }
     ProcessFieldValidationColor (valid, LoanExtraRepaymentDayField);
     context.ExtraRepaymentDay = extraRepaymentDay;
     validationResults.Add (valid);
 }
示例#10
0
 /// <summary>
 /// Tries to save the state.
 /// </summary>
 private void TrySaveState(LoanContext state)
 {
     lock (applicationSaveStateLock) {
         try {
             string savegameFilename = Path.Combine (Application.persistentDataPath, SaveStateFilename);
             SavedState saveState = new SavedState ();
             saveState.SavedDate = DateTime.Now;
             saveState.Context = state;
             BinaryFormatter formatter = new BinaryFormatter ();
             using (FileStream fs = File.Open (savegameFilename, FileMode.OpenOrCreate)) {
                 fs.SetLength (0);
                 formatter.Serialize (fs, saveState);
                 fs.Close ();
             }
         } catch (Exception ex) {
             MessagePanelController.SetMessage (string.Format ("Failed to save state: {0}", ex.Message));
             MessagePanelController.ShowMessagePanel ();
         }
     }
 }
示例#11
0
 /// <summary>
 /// Validates the loan balance.
 /// </summary>
 /// <param name="context">Context.</param>
 /// <param name="validationResults">Validation results.</param>
 private void ValidateLoanBalance(LoanContext context, List<bool> validationResults)
 {
     double balance = 0.0d;
     bool valid = double.TryParse (LoanBalanceField.text, NumberStyles.AllowCurrencySymbol | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.CurrentCulture, out balance);
     ProcessFieldValidationColor (valid, LoanBalanceField);
     context.Balance = balance;
     validationResults.Add (valid);
 }
示例#12
0
 /// <summary>
 /// Validates the input.
 /// </summary>
 /// <returns><c>true</c>, if input was validated, <c>false</c> otherwise.</returns>
 /// <param name="context">Context.</param>
 private bool ValidateInput(out LoanContext context)
 {
     List<bool> results = new List<bool> ();
     context = new LoanContext ();
     ValidateLoanStartDate (context, results);
     ValidateLoanTargetEndDate (context, results);
     ValidateLoanBalance (context, results);
     ValidateLoanInterestRate (context, results);
     ValidateLoanMinRepaymentDay (context, results);
     ValidateLoanMinRepaymentAmount (context, results);
     ValidateLoanExtraRepaymentDay (context, results);
     ValidateLoanExtraRepaymentAmount (context, results);
     context.TodaysDate = DateTime.Now;
     return(results.All (x => x));
 }
示例#13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LoanCalculator"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public LoanCalculator(LoanContext context)
 {
     this.context = context;
 }
示例#14
0
 /// <summary>
 /// Builds the sign text for a tower level.
 /// </summary>
 /// <param name="context">Context.</param>
 /// <param name="currentLevel">Current level.</param>
 /// <param name="year">Year.</param>
 /// <param name="month">Month.</param>
 /// <param name="groupedTransactions">Grouped transactions.</param>
 /// <param name="lastTransaction">Last transaction.</param>
 /// <param name="level">Level.</param>
 private void BuildSignTextForTowerLevel(LoanContext context, int currentLevel, int year, int month, IEnumerable<LoanTransaction> groupedTransactions, LoanTransaction lastTransaction, GameObject level)
 {
     DateTime timePoint = new DateTime (year, month, 1);
     string date = timePoint.ToString ("MMM yyyy");
     string balance = lastTransaction.Balance.ToString ("c0");
     WoodenSignController signController = level.transform.FindChild (Constants.CHILD_WOODEN_SIGN).GetComponent<WoodenSignController> ();
     signController.SetMonthBalanceText (string.Format ("{0}\n{1}", date, balance));
     string transactions = string.Empty;
     foreach (LoanTransaction tx in groupedTransactions) {
         transactions += ConvertTransactionType (tx.Type);
         transactions += tx.Debit > 0 ? " -" : " +";
         transactions += tx.Debit > 0 ? tx.Debit.ToString ("c0") : tx.Credit.ToString ("c0");
         transactions += "\n";
     }
     signController.SetTransactionsText (transactions);
     if (context.TargetEndDate.Year == year && context.TargetEndDate.Month == month) {
         signController.ChangMaterial (RedWoodenSignMaterial);
     } else {
         signController.ResetMaterial();
     }
 }
示例#15
0
 /// <summary>
 /// Validates the loan extra repayment amount.
 /// </summary>
 /// <param name="context">Context.</param>
 /// <param name="validationResults">Validation results.</param>
 private void ValidateLoanExtraRepaymentAmount(LoanContext context, List<bool> validationResults)
 {
     double extraRepaymentAmount = 0.0d;
     bool valid = true;
     if (!string.IsNullOrEmpty (LoanExtraRepaymentAmountField.text)) {
         valid = double.TryParse (LoanExtraRepaymentAmountField.text, NumberStyles.AllowCurrencySymbol | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.CurrentCulture, out extraRepaymentAmount);
         valid = valid && extraRepaymentAmount > 0;
         if (string.IsNullOrEmpty (LoanExtraRepaymentDayField.text)) {
             ProcessFieldValidationColor (false, LoanExtraRepaymentDayField);
             valid = false;
         }
     }
     ProcessFieldValidationColor (valid, LoanExtraRepaymentAmountField);
     context.ExtraRepaymentAmount = extraRepaymentAmount;
     validationResults.Add (valid);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LoanCalculationOutputStreamWriter"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="output">The output.</param>
 public LoanCalculationOutputStreamWriter(LoanContext context, LoanCalculationOutput output)
 {
     this.context = context;
     this.output = output;
 }
示例#17
0
 /// <summary>
 /// Handles the build requested.
 /// </summary>
 /// <param name="context">Context.</param>
 private void HandleBuildRequested(LoanContext context)
 {
     DebugText.text = string.Empty;
     TrySaveState (context);
     LoanCalculator calculator = new LoanCalculator (context);
     LoanCalculationOutput output = null;
     output = calculator.Calculate ();
     if (output.Failure) {
         Debug.LogError (output.FailureMessage);
         InputPanelController.SetErrorText(output.FailureMessage);
         return;
     }
     var groupedByMonthYear = output.Transactions.GroupBy (x => new { Month = x.Date.Month, Year = x.Date.Year });
     int towerLevels = groupedByMonthYear.Count ();
     List<GameObject> levels = TowerBuilder.BuildTower (towerLevels);
     int currentLevel = 0;
     foreach (var group in groupedByMonthYear) {
         int year = group.Key.Year;
         int month = group.Key.Month;
         IEnumerable<LoanTransaction> groupedTransactions = group.ToList ();
         LoanTransaction lastTransaction = group.Last ();
         BuildSignTextForTowerLevel (context, currentLevel, year, month, groupedTransactions, lastTransaction, levels [currentLevel]);
         currentLevel++;
     }
     CameraController.MaxY = levels.Last ().transform.position.y - 5;
     InputPanelController.HideInputPanel ();
     DebugText.text = string.Format ("Tower Levels: {0} / Total Interest: {1} / Loan Ends: {2}", towerLevels, output.TotalInterestPaid.ToString ("c"), output.LoanEndsDate.ToShortDateString ());
 }