add check for zero value in columns
This commit is contained in:
parent
819da95e70
commit
a43bb702e1
28
EvoCalculator.Core.Calculation/CheckTools.cs
Normal file
28
EvoCalculator.Core.Calculation/CheckTools.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace EvoCalculator.Core.Calculation
|
||||
{
|
||||
public class CheckTools<T>
|
||||
{
|
||||
private string ErrorZeroValue =
|
||||
"Невозможно осуществить расчет графика. При заданных параметрах получаются отрицательные значения";
|
||||
|
||||
public void CheckColumnForZeroValue(IEnumerable<decimal> Values)
|
||||
{
|
||||
if (Values.Skip(1).ToList().Exists(x => x < 0))
|
||||
{
|
||||
throw new Exception(ErrorZeroValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckColumnForZeroValue(IEnumerable<double> Values)
|
||||
{
|
||||
if (Values.Skip(1).ToList().Exists(x => x <= 0))
|
||||
{
|
||||
throw new Exception(ErrorZeroValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,11 +8,18 @@ namespace EvoCalculator.Core.Calculation.Columns
|
||||
{
|
||||
}
|
||||
|
||||
private void PostCheck()
|
||||
{
|
||||
new CheckTools<decimal>().CheckColumnForZeroValue(Values);
|
||||
}
|
||||
|
||||
public void ComputeValues(PreparedPayments preparedPayments, PreparedValues preparedValues)
|
||||
{
|
||||
for (var i = 1; i < Values.Length; i++) Values[i] = preparedPayments.Rows[i - 1].GpsCostPayment;
|
||||
|
||||
Values[0] = -XNPV;
|
||||
|
||||
PostCheck();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,11 @@ namespace EvoCalculator.Core.Calculation.Columns
|
||||
rate)
|
||||
{
|
||||
}
|
||||
|
||||
private void PostCheck()
|
||||
{
|
||||
new CheckTools<decimal>().CheckColumnForZeroValue(Values);
|
||||
}
|
||||
|
||||
public void ComputeValues(PreparedValues preparedValues, Constants.Calculation constants)
|
||||
{
|
||||
@ -29,6 +34,8 @@ namespace EvoCalculator.Core.Calculation.Columns
|
||||
|
||||
|
||||
Values[0] = -XNPV;
|
||||
|
||||
PostCheck();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -39,6 +39,8 @@ namespace EvoCalculator.Core.Calculation.Columns
|
||||
|
||||
private void PostCheck()
|
||||
{
|
||||
new CheckTools<decimal>().CheckColumnForZeroValue(Values);
|
||||
|
||||
if (Values[1] / Values.Skip(1).Sum() >= 0.5m)
|
||||
{
|
||||
throw new Exception(
|
||||
|
||||
@ -8,6 +8,11 @@ namespace EvoCalculator.Core.Calculation.Columns
|
||||
{
|
||||
}
|
||||
|
||||
private void PostCheck()
|
||||
{
|
||||
new CheckTools<decimal>().CheckColumnForZeroValue(Values);
|
||||
}
|
||||
|
||||
public void ComputeValues(Constants.Calculation calculation, PreparedValues preparedValues,
|
||||
SumCurrentColumn sumCurrentColumn, SumCurrentNegativeColumn sumCurrentNegativeColumn,
|
||||
SumCurrentInterestColumn sumCurrentInterestColumn, SumCurrentTLMColumn sumCurrentTlmColumn)
|
||||
@ -17,6 +22,8 @@ namespace EvoCalculator.Core.Calculation.Columns
|
||||
sumCurrentTlmColumn.Values[i] * (1 + (decimal) calculation.VatValue) -
|
||||
sumCurrentInterestColumn.Values[i] * (1 + (decimal) calculation.VatValue) *
|
||||
(decimal) preparedValues.Repayment;
|
||||
|
||||
PostCheck();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,11 @@ namespace EvoCalculator.Core.Calculation.Columns
|
||||
{
|
||||
}
|
||||
|
||||
private void PostCheck()
|
||||
{
|
||||
new CheckTools<decimal>().CheckColumnForZeroValue(Values);
|
||||
}
|
||||
|
||||
public void ComputeValues(Constants.Calculation constants, SumColumn sumColumn, PreparedValues preparedValues)
|
||||
{
|
||||
Values[0] = 0;
|
||||
@ -18,6 +23,8 @@ namespace EvoCalculator.Core.Calculation.Columns
|
||||
Values[i] = (decimal) (1 + constants.VatValue) * sumColumn.Values[i];
|
||||
|
||||
Values[0] = Sum;
|
||||
|
||||
PostCheck();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,11 +8,18 @@ namespace EvoCalculator.Core.Calculation.Columns
|
||||
{
|
||||
}
|
||||
|
||||
private void PostCheck()
|
||||
{
|
||||
new CheckTools<decimal>().CheckColumnForZeroValue(Values);
|
||||
}
|
||||
|
||||
public void ComputeValues(PreparedPayments preparedPayments, PreparedValues preparedValues)
|
||||
{
|
||||
for (var i = 1; i < Values.Length; i++) Values[i] = preparedPayments.Rows[i - 1].TlmCostPayment;
|
||||
|
||||
Values[0] = -XNPV;
|
||||
|
||||
PostCheck();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,11 @@ namespace EvoCalculator.Core.Calculation.Columns
|
||||
{
|
||||
}
|
||||
|
||||
private void PostCheck()
|
||||
{
|
||||
new CheckTools<decimal>().CheckColumnForZeroValue(Values);
|
||||
}
|
||||
|
||||
public void ComputeValues(Constants.Calculation constants, SumColumn sumColumn, PreparedValues preparedValues)
|
||||
{
|
||||
Values[0] = 0;
|
||||
@ -17,6 +22,8 @@ namespace EvoCalculator.Core.Calculation.Columns
|
||||
for (var i = 2; i < Values.Length; i++) Values[i] = (decimal) constants.VatValue * sumColumn.Values[i];
|
||||
|
||||
Values[0] = Sum;
|
||||
|
||||
PostCheck();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user