Esempio n. 1
0
        /// <summary>Outputs where Date Part function is used includes the array builder.
        /// <para>jparameters = JSON congifurations relating to this function</para>
        /// <para>jCategory = the whole configuration which is required to do the variable replace</para>
        /// <para>GroupID = current Group ID</para>
        /// <para>ItemID = current row ID</para>
        /// </summary>
        public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID)
        {
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();

            CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions();
            DateFunctions          DatesFunctions = new DateFunctions();
            ArrayBuildingFunctions ArrayBuilder   = new ArrayBuildingFunctions();
            DatePart parameters = (DatePart)javaScriptSerializ­er.Deserialize(jparameters, typeof(DatePart));

            string[] Date1parts = null;
            //Returns Array
            Date1parts = ArrayBuilder.InputArrayBuilder(parameters.Date1, jCategory, GroupID, ItemID);
            string Output = null;

            //Loop through the array to calculate each value in array
            foreach (string part in Date1parts)
            {
                dynamic  InputA = Config.VariableReplace(jCategory, part, GroupID, ItemID);
                DateTime Date1;
                DateTime.TryParse(InputA, out Date1);
                int DatePart = DatesFunctions.GetDatePart(parameters.Part, Date1);
                Output = Output + Convert.ToString(DatePart) + "~";
            }
            Output = Output.Remove(Output.Length - 1);
            return(Convert.ToString(Output));
        }
Esempio n. 2
0
        public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID)
        {
            ArrayBuildingFunctions ArrayBuilder = new ArrayBuildingFunctions();
            Factors parameters = (Factors)javaScriptSerializ­er.Deserialize(jparameters, typeof(Factors));

            string[] LookupValueparts   = null;
            string[] RowMatchValueparts = null;
            //Returns array
            LookupValueparts   = ArrayBuilder.InputArrayBuilder(parameters.LookupValue, jCategory, GroupID, ItemID);
            RowMatchValueparts = ArrayBuilder.InputArrayBuilder(parameters.RowMatchValue, jCategory, GroupID, ItemID);
            string Output      = null;
            int    Counter     = 0;
            string OutputValue = null;
            int    MaxLength   = ArrayBuilder.GetMaxLength(LookupValueparts, RowMatchValueparts);

            //Loop through the array to calculate each value in array
            for (int i = 0; i < MaxLength; i++)
            {
                dynamic InputA = null;
                dynamic InputB = null;
                //Gets the current array to use in the loop
                InputA = ArrayBuilder.GetArrayPart(LookupValueparts, Counter);
                InputB = ArrayBuilder.GetArrayPart(RowMatchValueparts, Counter);
                if (parameters.Interpolate == true)
                {
                    OutputValue = Interpolation(jparameters, InputA, InputB);
                }
                else
                {
                    OutputValue = Calculate(jparameters, InputA, InputB);
                }
                Output  = Output + OutputValue + "~";
                Counter = Counter + 1;
            }
            if (Output != null)
            {
                Output = Output.Remove(Output.Length - 1);
            }
            return(Output);
        }
Esempio n. 3
0
        /// <summary>Return where function is being built this is the value that should be passed back to the main calculation.
        /// <para>jparameters = JSON congifurations relating to this function</para>
        /// <para>jCategory = the whole configuration which is required to do the variable replace</para>
        /// <para>GroupID = current Group ID</para>
        /// <para>ItemID = current row ID</para>
        /// </summary>
        public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID)
        {
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();

            CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions();
            ArrayBuildingFunctions ArrayBuilder = new ArrayBuildingFunctions();
            Return parameters = (Return)javaScriptSerializ­er.Deserialize(jparameters, typeof(Return));

            string[] Return1parts = null;
            //Returns Array
            Return1parts = ArrayBuilder.InputArrayBuilder(parameters.Variable, jCategory, GroupID, ItemID);
            string Output = null;

            //Loop through the array to calculate each value in array
            foreach (string part in Return1parts)
            {
                dynamic InputA = Config.VariableReplace(jCategory, part, GroupID, ItemID);
                Output = Output + Convert.ToString(InputA) + "~";
            }
            Output = Output.Remove(Output.Length - 1);
            return(Convert.ToString(Output));
        }
Esempio n. 4
0
        /// <summary>Outputs where Maths Functions function is used, includes the array builder.
        /// <para>jparameters = JSON congifurations relating to this function</para>
        /// <para>jCategory = the whole configuration which is required to do the variable replace</para>
        /// <para>GroupID = current Group ID</para>
        /// <para>ItemID = current row ID</para>
        /// </summary>
        public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID, CategoryViewModel group)
        {
            JavaScriptSerializer   javaScriptSerializer = new JavaScriptSerializer();
            ArrayBuildingFunctions ArrayBuilder         = new ArrayBuildingFunctions();
            MathsFunctions         parameters           = (MathsFunctions)javaScriptSerializ­er.Deserialize(jparameters, typeof(MathsFunctions));

            string[] Numbers1parts = null;
            string[] Numbers2parts = null;
            //Returns array
            Numbers1parts = ArrayBuilder.InputArrayBuilder(parameters.Number1, jCategory, GroupID, ItemID);
            Numbers2parts = ArrayBuilder.InputArrayBuilder(parameters.Number2, jCategory, GroupID, ItemID);
            string  Output      = null;
            Decimal OutputValue = 0;
            //Gets Max Length of array so loops through all values
            int MaxLength = ArrayBuilder.GetMaxLength(Numbers1parts, Numbers2parts);
            int Counter   = 0;

            //Loop through the array to calculate each value in array
            for (int i = 0; i < MaxLength; i++)
            {
                dynamic InputA     = null;
                dynamic InputB     = null;
                decimal InputADeci = 0;
                decimal InputBDeci = 0;
                //Gets the current array to use in the loop
                InputA = ArrayBuilder.GetArrayPart(Numbers1parts, Counter);
                InputB = ArrayBuilder.GetArrayPart(Numbers2parts, Counter);
                decimal.TryParse(InputA, out InputADeci);
                decimal.TryParse(InputB, out InputBDeci);
                //Calculates the value required
                OutputValue = Calculate(parameters, InputADeci, InputBDeci, ItemID, group);
                Output      = Output + OutputValue + "~";
                Counter     = Counter + 1;
            }
            Output = Output.Remove(Output.Length - 1);
            return(Convert.ToString(Output));
        }
Esempio n. 5
0
        public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID, dynamic variable, string DataType)
        {
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();

            CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions();
            ArrayBuildingFunctions ArrayBuilder = new ArrayBuildingFunctions();

            string[] Parts = null;
            //Returns Array
            Parts = ArrayBuilder.InputArrayBuilder(variable, jCategory, GroupID, ItemID);
            string Output = null;

            //Loop through the array to calculate each value in array
            foreach (string part in Parts)
            {
                dynamic InputA = Config.VariableReplace(jCategory, part, GroupID, ItemID);
                if (DataType == "Date")
                {
                    DateTime Date1;
                    DateTime.TryParse(InputA, out Date1);
                    Output = Output + Convert.ToString(Date1.ToShortDateString()) + "~";
                }
                else if (DataType == "Decimal")
                {
                    Int16 Int1;
                    Int16.TryParse(InputA, out Int1);
                    Output = Output + Convert.ToString(Int1) + "~";
                }
                else
                {
                    Output = Output + Convert.ToString(InputA) + "~";
                }
            }
            Output = Output.Remove(Output.Length - 1);
            return(Convert.ToString(Output));
        }
Esempio n. 6
0
        /// <summary>Outputs where String Functions function is used, includes the array builder.
        /// <para>jparameters = JSON congifurations relating to this function</para>
        /// <para>jCategory = the whole configuration which is required to do the variable replace</para>
        /// <para>GroupID = current Group ID</para>
        /// <para>ItemID = current row ID</para>
        /// </summary>
        public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID)
        {
            JavaScriptSerializer   javaScriptSerializer = new JavaScriptSerializer();
            MathematicalFunctions  MathFunctions        = new MathematicalFunctions();
            ArrayBuildingFunctions ArrayBuilder         = new ArrayBuildingFunctions();
            StringFunctions        parameters           = (StringFunctions)javaScriptSerializ­er.Deserialize(jparameters, typeof(StringFunctions));

            string[] Numbers1parts = null;
            string[] Numbers2parts = null;
            string[] Numbers3parts = null;
            //Returns array
            Numbers1parts = ArrayBuilder.InputArrayBuilder(parameters.String1, jCategory, GroupID, ItemID);
            Numbers2parts = ArrayBuilder.InputArrayBuilder(parameters.Number1, jCategory, GroupID, ItemID);
            Numbers3parts = ArrayBuilder.InputArrayBuilder(parameters.String3, jCategory, 0, 0);
            string Output      = null;
            string OutputValue = null;
            //Gets Max Length of array so loops through all values
            int MaxLength = ArrayBuilder.GetMaxLength(Numbers1parts, Numbers2parts);

            //If Set only then
            if (Numbers3parts != null)
            {
                MaxLength = 1;
            }
            int Counter = 0;

            //Loop through the array to calculate each value in array
            for (int i = 0; i < MaxLength; i++)
            {
                dynamic InputA = null;
                dynamic InputB = null;
                dynamic InputC = null;
                //Gets the current array to use in the loop
                InputA = ArrayBuilder.GetArrayPart(Numbers1parts, Counter);
                InputB = ArrayBuilder.GetArrayPart(Numbers2parts, Counter);
                InputC = ArrayBuilder.GetArrayPart(Numbers3parts, Counter);

                string InputAString = null;
                int    InputBDeci   = 0;
                string InputCString = null;

                InputAString = Convert.ToString(InputA);
                int.TryParse(InputB, out InputBDeci);
                InputCString = Convert.ToString(InputC);
                //Calculates the value required
                if (parameters.Type == "Left")
                {
                    OutputValue = InputAString.Substring(0, InputBDeci);
                }
                else if (parameters.Type == "Right")
                {
                    OutputValue = InputAString.Substring(InputAString.Length - InputBDeci);
                }
                else if (parameters.Type == "Set")
                {
                    OutputValue = InputCString;
                }
                else if (parameters.Type == "Find")
                {
                    int FindValue = InputAString.IndexOf(parameters.String2);

                    if (FindValue != -1)
                    {
                        OutputValue = Convert.ToString(FindValue);
                    }
                    else
                    {
                        OutputValue = "0";
                    }
                }
                else if (parameters.Type == "Len")
                {
                    OutputValue = Convert.ToString(InputAString.Length);
                }
                Output  = Output + OutputValue + "~";
                Counter = Counter + 1;
            }
            Output = Output.Remove(Output.Length - 1);
            return(Convert.ToString(Output));
        }
Esempio n. 7
0
        /// <summary>Outputs where Period function is used, includes the array builder.
        /// <para>jparameters = JSON congifurations relating to this function</para>
        /// <para>jCategory = the whole configuration which is required to do the variable replace</para>
        /// <para>GroupID = current Group ID</para>
        /// <para>ItemID = current row ID</para>
        /// </summary>
        public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID)
        {
            JavaScriptSerializer   javaScriptSerializer = new JavaScriptSerializer();
            DateFunctions          DateFunctions        = new DateFunctions();
            ArrayBuildingFunctions ArrayBuilder         = new ArrayBuildingFunctions();
            Period Dates      = new Period();
            Period parameters = (Period)javaScriptSerializ­er.Deserialize(jparameters, typeof(Period));

            string[] Date1parts = null;
            string[] Date2parts = null;
            //Returns array
            Date1parts = ArrayBuilder.InputArrayBuilder(parameters.Date1, jCategory, GroupID, ItemID);
            Date2parts = ArrayBuilder.InputArrayBuilder(parameters.Date2, jCategory, GroupID, ItemID);
            string OutputValue = null;
            string Output      = null;
            int    Counter     = 0;
            //Gets Max Length of array so loops through all values
            int MaxLength = ArrayBuilder.GetMaxLength(Date1parts, Date2parts);

            //Loop through the array to calculate each value in array
            for (int i = 0; i < MaxLength; i++)
            {
                dynamic InputA = null;
                dynamic InputB = null;
                InputA  = ArrayBuilder.GetArrayPart(Date1parts, Counter);
                InputB  = ArrayBuilder.GetArrayPart(Date2parts, Counter);
                Counter = Counter + 1;
                //Checks if Inputs are OK to proceed in using the calculation
                if (InputA != "" && InputB != "" && InputA != "01/01/0001" && InputB != "01/01/0001")
                {
                    DateTime Date1;
                    DateTime Date2;
                    if (InputA != null)
                    {
                        DateTime.TryParse(InputA, out Date1);
                    }
                    else
                    {
                        Date1 = Convert.ToDateTime("01/01/0001");
                    }

                    if (InputB != null)
                    {
                        DateTime.TryParse(InputB, out Date2);
                    }
                    else
                    {
                        Date2 = Convert.ToDateTime("01/01/0001");
                    }
                    String  DateAdjustmentType = parameters.DateAdjustmentType;
                    Boolean Inclusive          = parameters.Inclusive;
                    Double  DaysinYear         = parameters.DaysinYear;
                    //Calcuates the relevant period
                    if (Date1 <= Date2)
                    {
                        if (DateAdjustmentType == "YearsDays")
                        {
                            OutputValue = Convert.ToString(DateFunctions.YearsDaysBetween(Date1, Date2, Inclusive, DaysinYear));
                        }
                        else if (DateAdjustmentType == "YearsMonths")
                        {
                            OutputValue = Convert.ToString(DateFunctions.YearsMonthsBetween(Date1, Date2, Inclusive, DaysinYear));
                        }

                        else if (DateAdjustmentType == "Years")
                        {
                            OutputValue = Convert.ToString(DateFunctions.YearsBetween(Date1, Date2, Inclusive, DaysinYear));
                        }

                        else if (DateAdjustmentType == "Months")
                        {
                            OutputValue = Convert.ToString(DateFunctions.GetMonthsBetween(Date1, Date2, Inclusive));
                        }

                        else if (DateAdjustmentType == "Days")
                        {
                            OutputValue = Convert.ToString(DateFunctions.DaysBetween(Date1, Date2, Inclusive, DaysinYear));
                        }
                        else
                        {
                            OutputValue = "0";
                        }
                    }
                    else
                    {
                        OutputValue = Convert.ToString(0);
                    }
                    Output = Output + OutputValue + "~";
                }
                else
                {
                    OutputValue = Convert.ToString(0);
                    Output      = Output + OutputValue + "~";
                }
            }
            if (Output != null)
            {
                Output = Output.Remove(Output.Length - 1);
            }
            return(Output);
        }
Esempio n. 8
0
        /// <summary>Outputs Date Adjustment function is used, includes the array builder.
        /// <para>jparameters = JSON congifurations relating to this function</para>
        /// <para>jCategory = the whole configuration which is required to do the variable replace</para>
        /// <para>GroupID = current Group ID</para>
        /// <para>ItemID = current row ID</para>
        /// </summary>
        public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID)
        {
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();

            CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions();
            DateFunctions          DatesFunctions = new DateFunctions();
            ArrayBuildingFunctions ArrayBuilder   = new ArrayBuildingFunctions();
            Dates parameters = (Dates)javaScriptSerializ­er.Deserialize(jparameters, typeof(Dates));

            if (parameters.Type == "Today")
            {
                return(DateTime.Now.ToShortDateString());
            }
            string[] Date1parts = null;
            string[] Date2parts = null;
            //Returns array
            Date1parts = ArrayBuilder.InputArrayBuilder(parameters.Date1, jCategory, GroupID, ItemID);
            Date2parts = ArrayBuilder.InputArrayBuilder(parameters.Date2, jCategory, GroupID, ItemID);
            string Output  = null;
            int    Counter = 0;
            //Gets Max Length of array so loops through all values
            int MaxLength = ArrayBuilder.GetMaxLength(Date1parts, Date2parts);

            //Loop through the array to calculate each value in array
            for (int i = 0; i < MaxLength; i++)
            {
                dynamic InputA = null;
                dynamic InputB = null;
                //Gets the current array to use in the loop
                InputA = ArrayBuilder.GetArrayPart(Date1parts, Counter);
                InputB = ArrayBuilder.GetArrayPart(Date2parts, Counter);
                dynamic  InputC = Config.VariableReplace(jCategory, parameters.Period, GroupID, ItemID);
                DateTime Date1;
                DateTime Date2;
                Decimal  Period;
                //Data output checker
                if (InputA != null)
                {
                    DateTime.TryParse(InputA, out Date1);
                }
                else
                {
                    Date1 = Convert.ToDateTime("01/01/0001");
                }

                if (InputB != null)
                {
                    DateTime.TryParse(InputB, out Date2);
                }
                else
                {
                    Date2 = Convert.ToDateTime("01/01/0001");
                }
                Decimal.TryParse(InputC, out Period);
                string date = DatesFunctions.DateAdjustment(parameters.Type, Convert.ToString(Date1), Convert.ToString(Date2), parameters.PeriodType, Period, parameters.Adjustment, parameters.Day, parameters.Month);
                Output  = Output + date + "~";
                Counter = Counter + 1;
            }
            if (Output != null)
            {
                Output = Output.Remove(Output.Length - 1);
            }
            return(Convert.ToString(Output));
        }