Exemplo n.º 1
0
        public void TestAdd_Fail()
        {
            var input1 = "a";
            var input2 = "12";

            _ = CalcHelper.Add(input1, input2);
        }
        public static void DelegateMethod(string name, FunctionArgs args)
        {
            string indicatorName;

            Screen2.Entity.Indicator ind;
            int offset;

            switch (name.ToLower())
            {
            case "iv":
            case "ivalue":
                indicatorName = args.Parameters[0].ParsedExpression.ToString();
                ind           = ExpressionManager.Indicators[ExpressionManager.CurrentIndex];

                args.Result = ObjHelper.GetPropValue(ind, CalcHelper.PropName(indicatorName));
                break;

            case "ivd":
            case "ivalue_d":
                indicatorName = args.Parameters[0].ParsedExpression.ToString();
                offset        = int.Parse(args.Parameters[1].Evaluate().ToString());
                ind           = ExpressionManager.Indicators[ExpressionManager.CurrentIndex + offset];

                args.Result = ObjHelper.GetPropValue(ind, CalcHelper.PropName(indicatorName));
                break;
                //default:
                //    throw new ArgumentException(string.Format("custom function {0} is not defined", name));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> amount received at maturity for a fully invested security.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 4 - 5 items: settlement, maturity, investment, discount, [basis].
        /// </para>
        /// <para>
        /// Settlement is the security's settlement date.
        /// The security settlement date is the date after the issue date when the security is traded to the buyer.
        /// </para>
        /// <para>
        /// Maturity is the security's maturity date. The maturity date is the date when the security expires.
        /// </para>
        /// <para>
        /// Investment is the amount invested in the security.
        /// </para>
        /// <para>
        /// Discount is the security's discount rate.
        /// </para>
        /// <para>
        /// Basis is the type of day count basis to use.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            DateTime time  = CalcConvert.ToDateTime(args[0]);
            DateTime time2 = CalcConvert.ToDateTime(args[1]);
            double   num   = CalcConvert.ToDouble(args[2]);
            double   num2  = CalcConvert.ToDouble(args[3]);
            int      basis = CalcHelper.ArgumentExists(args, 4) ? CalcConvert.ToInt(args[4]) : 0;

            if (DateTime.Compare(time, time2) >= 0)
            {
                return(CalcErrors.Number);
            }
            if (((num <= 0.0) || (num2 <= 0.0)) || ((basis < 0) || (4 < basis)))
            {
                return(CalcErrors.Number);
            }
            double num4 = FinancialHelper.days_monthly_basis(time, time2, basis);
            double num5 = FinancialHelper.annual_year_basis(time, basis);

            if ((num4 <= 0.0) || (num5 <= 0.0))
            {
                return(CalcErrors.Number);
            }
            double num6 = 1.0 - ((num2 * num4) / num5);

            if (num6 <= 0.0)
            {
                return(CalcErrors.Number);
            }
            return((double)(num / num6));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> price per $100 face value of a security that pays periodic interest.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 6 - 7 items: settlement, maturity, rate, yld, redemption, frequency, [basis].
        /// </para>
        /// <para>
        /// Settlement is the security's settlement date.
        /// The security settlement date is the date after the issue date when the security is traded to the buyer.
        /// </para>
        /// <para>
        /// Maturity is the security's maturity date. The maturity date is the date when the security expires.
        /// </para>
        /// <para>
        /// Rate is the security's annual coupon rate.
        /// </para>
        /// <para>
        /// Yld is the security's annual yield.
        /// </para>
        /// <para>
        /// Redemption is the security's redemption value per $100 face value.
        /// </para>
        /// <para>
        /// Frequency is the number of coupon payments per year. For annual payments, frequency = 1; for semiannual, frequency = 2; for quarterly, frequency = 4.
        /// </para>
        /// <para>
        /// Basis is the type of day count basis to use.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            DateTime time       = CalcConvert.ToDateTime(args[0]);
            DateTime time2      = CalcConvert.ToDateTime(args[1]);
            double   rate       = CalcConvert.ToDouble(args[2]);
            double   yield      = CalcConvert.ToDouble(args[3]);
            double   redemption = CalcConvert.ToDouble(args[4]);
            int      freq       = CalcConvert.ToInt(args[5]);
            int      basis      = CalcHelper.ArgumentExists(args, 6) ? CalcConvert.ToInt(args[6]) : 0;

            if (((yield < 0.0) || (rate < 0.0)) || (redemption == 0.0))
            {
                return(CalcErrors.Number);
            }
            if ((basis < 0) || (basis > 4))
            {
                return(CalcErrors.Number);
            }
            if (((freq != 1) && (freq != 2)) && (freq != 4))
            {
                return(CalcErrors.Number);
            }
            if (DateTime.Compare(time, time2) > 0)
            {
                return(CalcErrors.Number);
            }
            return((double)FinancialHelper.price(time, time2, rate, yield, redemption, freq, basis));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns one value if a condition you specify evaluates to <see langword="true" />
        /// and another value if it evaluates to <see langword="false" />.
        /// </summary>
        /// <param name="args">
        /// <para>
        /// The args contains three items: logical_test, value_if_true and value_if_false.
        /// </para>
        /// <para>
        /// logical_test is any value or expression that can be evaluated to <see langword="true" /> or <see langword="false" />.
        /// For example, A10=100 is a logical expression; if the value in cell A10 is equal to 100,
        /// the expression evaluates to <see langword="true" />. Otherwise, the expression evaluates to <see langword="false" />.
        /// This argument can use any comparison calculation operator.
        /// </para>
        /// <para>
        /// value_if_true is the value that is returned if logical_test is <see langword="true" />. For example,
        /// if this argument is the text string "Within budget" and the logical_test argument evaluates to <see langword="true" />,
        /// then the IF function displays the text "Within budget". If logical_test is <see langword="true" /> and value_if_true is blank,
        /// this argument returns 0 (zero). To display the word <see langword="true" />, use the logical value <see langword="true" /> for this argument.
        /// Value_if_true can be another formula.
        /// </para>
        /// <para>
        /// value_if_false is the value that is returned if logical_test is <see langword="false" />. For example,
        /// if this argument is the text string "Over budget" and the logical_test argument evaluates to <see langword="false" />,
        /// then the IF function displays the text "Over budget". If logical_test is <see langword="false" /> and value_if_false is omitted,
        /// (that is, after value_if_true, there is no comma), then the logical value <see langword="false" /> is returned.
        /// If logical_test is <see langword="false" /> and value_if_false is blank (that is, after value_if_true,
        /// there is a comma followed by the closing parenthesis),
        /// then the value 0 (zero) is returned. Value_if_false can be another formula.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Object" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            object param = args[0];
            object obj3  = args[1];
            object obj4  = CalcHelper.ArgumentExists(args, 2) ? args[2] : ((bool)false);

            if (CalcHelper.TryExtractToSingleValue(param, out param))
            {
                return(EvaluateSingleValue(param, obj3, obj4));
            }
            bool      flag  = CalcHelper.TryExtractToSingleValue(obj3, out obj3);
            bool      flag2 = CalcHelper.TryExtractToSingleValue(obj4, out obj4);
            CalcArray array = param as CalcArray;

            object[,] values = new object[array.RowCount, array.ColumnCount];
            for (int i = 0; i < array.RowCount; i++)
            {
                for (int j = 0; j < array.ColumnCount; j++)
                {
                    values[i, j] = EvaluateSingleValue(array.GetValue(i, j), flag ? obj3 : CalcHelper.GetArrayValue(obj3 as CalcArray, i, j), flag2 ? obj4 : CalcHelper.GetArrayValue(obj4 as CalcArray, i, j));
                }
            }
            return(new ConcreteArray <object>(values));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns the logarithm of a number to the base you specify.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 - 2 items: number, [base].
        /// </para>
        /// <para>
        /// Number is the positive real number for which you want the logarithm.
        /// </para>
        /// <para>
        /// [Base] is the base of the logarithm. If base is omitted, it is assumed to be 10.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            double num;
            double num2;

            base.CheckArgumentsLength(args);
            if (!CalcConvert.TryToDouble(args[0], out num, true))
            {
                return(CalcErrors.Value);
            }
            if (CalcHelper.ArgumentExists(args, 1))
            {
                if (!CalcConvert.TryToDouble(args[1], out num2, true))
                {
                    return(CalcErrors.Value);
                }
            }
            else
            {
                num2 = 10.0;
            }
            if ((num <= 0.0) || (num2 <= 0.0))
            {
                return(CalcErrors.Number);
            }
            if (num2 == 1.0)
            {
                return(CalcErrors.DivideByZero);
            }
            return(CalcConvert.ToResult(Math.Log(num, num2)));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Evaluates the function with the given arguments.
        /// </summary>
        /// <param name="args">Arguments for the function evaluation</param>
        /// <returns>
        /// Result of the function applied to the arguments
        /// </returns>
        public override object Evaluate(object[] args)
        {
            double num    = CalcConvert.ToDouble(args[0]);
            string str    = CalcConvert.ToString(args[1]);
            string str2   = CalcConvert.ToString(args[2]);
            bool   flag   = CalcHelper.ArgumentExists(args, 3) ? CalcConvert.ToBool(args[3]) : false;
            int    prec   = CalcHelper.ArgumentExists(args, 4) ? CalcConvert.ToInt(args[4]) : 3;
            int    digits = 0;

            if (prec >= 3)
            {
                if (!flag)
                {
                    digits = FinancialHelper.displayPrecision(str2);
                }
                if (!CalcHelper.ArgumentExists(args, 4))
                {
                    prec = FinancialHelper.calcPrecision(str);
                }
                double num4 = 0.0;
                double num5 = FinancialHelper.one_euro(str, prec);
                double num6 = FinancialHelper.one_euro(str2, prec);
                if ((num5 >= 0.0) && (num6 >= 0.0))
                {
                    num4 = (num * num6) / num5;
                    if (!flag)
                    {
                        num4 = Math.Round(num4, digits);
                    }
                    return((double)num4);
                }
            }
            return(CalcErrors.Value);
        }
Exemplo n.º 8
0
        public static void WaitForPlayers()
        {
            Send(BitConverter.GetBytes(true), EP2PSend.k_EP2PSendReliable, BB_Ready);

            while (_playersReadyCount < OtherPlayers.Count)
            {
                LoadingScreen.LoadingText = "Waiting for other players...";
                ReceivePackets(BB_Ready);
            }

            if (IsHost)
            {
                long time = DateTime.UtcNow.Ticks + 5 * 1000000;
                _hasStartTime = true;
                _startTime    = new DateTime(time);
                Send(CalcHelper.ToByteArray(time), EP2PSend.k_EP2PSendReliable, BB_StartTime);
            }
            else
            {
                while (!_hasStartTime)
                {
                    ReceivePackets(BB_StartTime);
                }
            }

            while (DateTime.UtcNow.Ticks < _startTime.Ticks)
            {
                LoadingScreen.LoadingText = "Starting game...";
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Counts the cells that contain numbers in a field (column) of
        /// records in a list or database that match conditions that you specify.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 3 items: database, field, criteria.
        /// </para>
        /// <para>
        /// Database is the range of cells that makes up the list or database.
        /// A database is a list of related data in which rows of related
        /// information are records, and columns of data are fields.
        /// The first row of the list contains labels for each column.
        /// </para>
        /// <para>
        /// Field indicates which column is used in the function.
        /// Enter the column label enclosed between double quotation marks,
        /// such as "Age" or "Yield," or a number (without quotation marks)
        /// that represents the position of the column within the list:
        /// 1 for the first column, 2 for the second column, and so on.
        /// </para>
        /// <para>
        /// Criteria is the range of cells that contains the conditions you
        /// specify. You can use any range for the criteria argument,
        /// as long as it includes at least one column label and at least
        /// one cell below the column label in which you specify a condition for the column.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Object" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            if (((args[0] == null) || (args[1] == null)) || (args[2] == null))
            {
                throw new ArgumentNullException();
            }
            CalcArray database = CalcConvert.ToArray(args[0]);
            object    field    = args[1];
            CalcArray criteria = CalcConvert.ToArray(args[2]);
            double    num      = 0.0;

            if (CalcHelper.ArgumentExists(args, 1))
            {
                IEnumerator enumerator = new DatabaseEnumerator(database, field, criteria);
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current != null)
                    {
                        num++;
                    }
                }
            }
            else
            {
                IEnumerator enumerator2 = new DatabaseEnumerator(database, criteria);
                while (enumerator2.MoveNext())
                {
                    num++;
                }
            }
            return(CalcConvert.ToResult(num));
        }
Exemplo n.º 10
0
        private static void SpawnRain()
        {
            if (spawnTimer.TimeElapsedInMilliSeconds > 50)
            {
                spawnTimer.Reset();
                int[] indices = GameWorld.ChunkManager.GetVisibleIndexes();
                if (indices == null)
                {
                    return;
                }

                int width    = GameWorld.ChunkManager.GetVisibileWidth();
                int starting = indices[0];

                // Do the top row as always.
                for (int i = starting; i < starting + width; i++)
                {
                    Tile tile = GameWorld.GetTile(i);
                    ParticleSystem.Add(Particles.ParticleType.Rain, CalcHelper.GetRandXAndY(tile.DrawRectangle), new Vector2(0, 8), Color.Blue);
                }

                // This spawns particles on areas that have just been put into view.
                var newIndices = indices.Except(lastIndices);

                foreach (var i in newIndices)
                {
                    Tile tile = GameWorld.GetTile(i);
                    ParticleSystem.Add(Particles.ParticleType.Rain, CalcHelper.GetRandXAndY(tile.DrawRectangle), new Vector2(0, 8), Color.Blue);
                }

                lastIndices = indices;
            }
        }
Exemplo n.º 11
0
        private static void ReceivePackets(int channel = -1)
        {
            int i   = 0;
            int max = 10;

            if (channel != -1)
            {
                i   = channel;
                max = channel + 1;
            }
            for (i = 0; i < max; i++)
            {
                while (SteamNetworking.IsP2PPacketAvailable(out uint messageSize, i))
                {
                    Console.WriteLine("Packet available of size: " + messageSize);
                    byte[] pubDest = new byte[messageSize];
                    if (SteamNetworking.ReadP2PPacket(pubDest, messageSize, out uint bytesRead, out CSteamID steamIdRemote, i))
                    {
                        switch (i)
                        {
                        case BB_LevelData:
                            IsActive = true;
                            WorldConfigFile config = (WorldConfigFile)CalcHelper.ConvertToObject(pubDest);
                            config.LoadIntoEditor();
                            break;

                        case BB_Ready:
                            _playersReadyCount++;
                            break;

                        case BB_StartTime:
                            _startTime = new DateTime((long)CalcHelper.ConvertToObject(pubDest));
                            break;

                        case BB_TileIdChange:
                            Packet.TileIdChange packet = (Packet.TileIdChange)CalcHelper.ConvertToObject(pubDest);
                            LevelEditor.UpdateTileFromP2P(packet);
                            break;

                        case BB_AllEntities:
                            UpdateEntities(pubDest);
                            break;

                        case BB_EntityUpdate:
                            UpdateEntities(pubDest);
                            break;
                        }

                        // Relay message to others.
                        if (IsHost)
                        {
                            var allButSender = (from client in OtherPlayers
                                                where client != steamIdRemote
                                                select client).ToList();
                            Send(pubDest, EP2PSend.k_EP2PSendReliable, i, allButSender);
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        public void TestDivide_Fail()
        {
            var input1 = "x";
            var input2 = "0";

            _ = CalcHelper.Divide(input1, input2);
        }
Exemplo n.º 13
0
        public void TestMultiply_Fail()
        {
            var input1 = "29.3";
            var input2 = "a";

            _ = CalcHelper.Multiply(input1, input2);
        }
Exemplo n.º 14
0
        public void TestSubtract_Fail()
        {
            var input1 = "29.3";
            var input2 = "";

            _ = CalcHelper.Subtract(input1, input2);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> payment for a loan with constant payments and fixed interest.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 3 - 5 items: rate, nper, pv, [fv], [type].
        /// </para>
        /// <para>
        /// Rate is the interest rate for the loan.
        /// </para>
        /// <para>
        /// Nper is the total number of payments for the loan.
        /// </para>
        /// <para>
        /// Pv is the present value, or the total amount that a series of future payments is worth now;
        /// also known as the principal.
        /// </para>
        /// <para>
        /// Fv is the future value, or a cash balance you want to attain after the last payment is made.
        /// If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0.
        /// </para>
        /// <para>
        /// Type is the number 0 (zero) or 1 and indicates when payments are due.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            double num  = CalcConvert.ToDouble(args[0]);
            double y    = CalcConvert.ToDouble(args[1]);
            double num3 = CalcConvert.ToDouble(args[2]);
            double num4 = CalcHelper.ArgumentExists(args, 3) ? CalcConvert.ToDouble(args[3]) : 0.0;
            double num5 = CalcHelper.ArgumentExists(args, 4) ? CalcConvert.ToDouble(args[4]) : 0.0;

            if (num5 != 0.0)
            {
                num5 = 1.0;
            }
            if (num == 0.0)
            {
                if (y == 0.0)
                {
                    return(CalcErrors.DivideByZero);
                }
                return(CalcConvert.ToResult(-(num3 + num4) / y));
            }
            if (y == 0.0)
            {
                return(CalcErrors.DivideByZero);
            }
            return(CalcConvert.ToResult(-((num3 * Math.Pow(1.0 + num, y)) + num4) / (((1.0 + (num * num5)) * (Math.Pow(1.0 + num, y) - 1.0)) / num)));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Gets the identity of current expressions based on <paramref name="row" /> and <paramref name="column" />.
        /// </summary>
        /// <param name="row">The base row.</param>
        /// <param name="column">The base column.</param>
        /// <returns></returns>
        public override CalcIdentity GetId(int row, int column)
        {
            switch (this.RangeType)
            {
            case CalcRangeType.Row:
            {
                int num  = this.StartRowRelative ? CalcHelper.NormalizeRowIndex(this.StartRow + row, 0xfffff) : this.StartRow;
                int num2 = this.EndRowRelative ? CalcHelper.NormalizeRowIndex(this.EndRow + row, 0xfffff) : this.EndRow;
                base.Sort(ref num, ref num2);
                return(new CalcSheetRangeIdentity(this.StartSource, this.EndSource, num, CalcHelper.NormalizeRowIndex((num2 - num) + 1, 0xfffff), true));
            }

            case CalcRangeType.Column:
            {
                int num3 = this.StartColumnRelative ? CalcHelper.NormalizeRowIndex(this.StartColumn + column, 0xfffff) : this.StartColumn;
                int num4 = this.EndColumnRelative ? CalcHelper.NormalizeRowIndex(this.EndColumn + column, 0xfffff) : this.EndColumn;
                base.Sort(ref num3, ref num4);
                return(new CalcSheetRangeIdentity(this.StartSource, this.EndSource, num3, CalcHelper.NormalizeRowIndex((num4 - num3) + 1, 0xfffff), false));
            }

            case CalcRangeType.Sheet:
                return(new CalcSheetRangeIdentity(this.StartSource, this.EndSource));
            }
            bool flag = (this.EndRow == -2147483648) || (this.EndColumn == -2147483648);
            int  num5 = this.StartRowRelative ? CalcHelper.NormalizeRowIndex(this.StartRow + row, 0xfffff) : this.StartRow;
            int  num6 = this.EndRowRelative ? CalcHelper.NormalizeRowIndex(this.EndRow + row, 0xfffff) : this.EndRow;
            int  num7 = this.StartColumnRelative ? CalcHelper.NormalizeRowIndex(this.StartColumn + column, 0xfffff) : this.StartColumn;
            int  num8 = this.EndColumnRelative ? CalcHelper.NormalizeRowIndex(this.EndColumn + column, 0xfffff) : this.EndColumn;

            base.Sort(ref num5, ref num6);
            base.Sort(ref num7, ref num8);
            int rowCount = flag ? 1 : CalcHelper.NormalizeRowIndex((num6 - num5) + 1, 0xfffff);

            return(new CalcSheetRangeIdentity(this.StartSource, this.EndSource, num5, num7, rowCount, flag ? 1 : CalcHelper.NormalizeRowIndex((num8 - num7) + 1, 0xfffff)));
        }
Exemplo n.º 17
0
        private void Update()
        {
//            if (fadeFrames > 0)
//            {
//                fadeFrames--;

//                if (fadeFrames <= 0)
//                {
//                    Destroy(gameObject);
//                }
//            }

            if (Speed != Vector2.zero)
            {
                if (Speed.x != 0)
                {
                    Speed.x = CalcHelper.Approach(Speed.x, 0, friction * Time.deltaTime);
                }

                if (Speed.y != 0)
                {
                    Speed.y = CalcHelper.Approach(Speed.y, 0, friction * Time.deltaTime);
                }
            }
        }
Exemplo n.º 18
0
        private void BtnOkClick(object sender, EventArgs e)
        {
            RefreshUI();
            if (!btnOk.Enabled)
            {
                DialogResult = DialogResult.None;
                return;
            }

            using (var context = new DataClassesDataContext())
            {
                var paymentPeriod = new PaymentPeriod {
                    Year = Year, Month = Month
                };
                context.PaymentPeriods.InsertOnSubmit(paymentPeriod);
                context.SubmitChanges();
            }

            if (MessageBox.Show(this, string.Format("Расчетный период за {0} создан.\r\nВы хотите сформировать начисления?", UIHelper.PeriodToString(Year, Month)), "Подтверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
            {
                using (var context = new DataClassesDataContext())
                {
                    CalcHelper.MakePayments(context, Year, Month);
                }
            }
        }
Exemplo n.º 19
0
        private void ApplyNewConfig(object sender, EventArgs e)
        {
            int Year = DateTime.Today.Year;

            int.TryParse(DateTime.Today.Month > 8 ? UserSession.User.Settings.SchoolYear.Substring(0, 4) : UserSession.User.Settings.SchoolYear.Substring(5, 4), out Year);
            DateTime CurrentDate = new DateTime(Year, DateTime.Today.Month, DateTime.Today.Day);

            EndOfSemester   = CalcHelper.StartDateOfSemester2(CurrentDate).AddDays(-1);
            EndOfSchoolYear = CalcHelper.EndDateOfSchoolYear(UserSession.User.Settings.SchoolYear);

            if (rbOkres == null)
            {
                if (CurrentDate <= EndOfSemester)
                {
                    rbSemestr.Checked = true;
                }
                else
                {
                    rbRokSzkolny.Checked = true;
                }
            }
            else
            {
                rbSemestr_CheckedChanged(rbOkres, null);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Gets the identity of current expressions based on <paramref name="row" /> and <paramref name="column" />.
        /// </summary>
        /// <param name="row">The base row.</param>
        /// <param name="column">The base column.</param>
        /// <returns></returns>
        public override CalcIdentity GetId(int row, int column)
        {
            switch (this.RangeType)
            {
            case CalcRangeType.Row:
            {
                int num  = this.StartRowRelative ? CalcHelper.NormalizeRowIndex(this.StartRow + row, 0xfffff) : this.StartRow;
                int num2 = this.EndRowRelative ? CalcHelper.NormalizeRowIndex(this.EndRow + row, 0xfffff) : this.EndRow;
                base.Sort(ref num, ref num2);
                return(new CalcExternalRangeIdentity(base.Source, num, CalcHelper.NormalizeRowIndex((num2 - num) + 1, 0xfffff), true));
            }

            case CalcRangeType.Column:
            {
                int num3 = this.StartColumnRelative ? CalcHelper.NormalizeRowIndex(this.StartColumn + column, 0xfffff) : this.StartColumn;
                int num4 = this.EndColumnRelative ? CalcHelper.NormalizeRowIndex(this.EndColumn + column, 0xfffff) : this.EndColumn;
                base.Sort(ref num3, ref num4);
                return(new CalcExternalRangeIdentity(base.Source, num3, CalcHelper.NormalizeRowIndex((num4 - num3) + 1, 0xfffff), false));
            }

            case CalcRangeType.Sheet:
                return(new CalcExternalRangeIdentity(base.Source));
            }
            int num5 = this.StartRowRelative ? CalcHelper.NormalizeRowIndex(this.StartRow + row, 0xfffff) : this.StartRow;
            int num6 = this.EndRowRelative ? CalcHelper.NormalizeRowIndex(this.EndRow + row, 0xfffff) : this.EndRow;
            int num7 = this.StartColumnRelative ? CalcHelper.NormalizeRowIndex(this.StartColumn + column, 0xfffff) : this.StartColumn;
            int num8 = this.EndColumnRelative ? CalcHelper.NormalizeRowIndex(this.EndColumn + column, 0xfffff) : this.EndColumn;

            base.Sort(ref num5, ref num6);
            base.Sort(ref num7, ref num8);
            return(new CalcExternalRangeIdentity(base.Source, num5, num7, CalcHelper.NormalizeRowIndex((num6 - num5) + 1, 0xfffff), CalcHelper.NormalizeRowIndex((num8 - num7) + 1, 0xfffff)));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Summarizes the extends of the given <paramref name="elements"/> in orientation direction.
        /// </summary>
        /// <param name="elements">Elements to summarize.</param>
        /// <param name="orientation">Orientation in which the extends should be summarized.</param>
        /// <param name="startIndex">Index of the first element, inclusive.</param>
        /// <param name="endIndex">Index of the last element, exclusive.</param>
        /// <returns></returns>
        protected static double SumActualExtendsInOrientationDirection(IList <FrameworkElement> elements, Orientation orientation, int startIndex, int endIndex)
        {
            CalcHelper.Bound(ref startIndex, 0, elements.Count - 1);
            CalcHelper.Bound(ref endIndex, 0, elements.Count); // End index is exclusive
            if (startIndex == endIndex || elements.Count == 0)
            {
                return(0);
            }
            bool invert = startIndex > endIndex;

            if (invert)
            {
                int tmp = startIndex;
                startIndex = endIndex;
                endIndex   = tmp;
            }
            double result = 0;

            if (orientation == Orientation.Horizontal)
            {
                for (int i = startIndex; i < endIndex; i++)
                {
                    result += elements[i].ActualWidth;
                }
            }
            else
            {
                for (int i = startIndex; i < endIndex; i++)
                {
                    result += elements[i].ActualHeight;
                }
            }
            return(invert ? -result : result);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Focuses the last line if the first line currently has focus
        /// </summary>
        /// <returns>true if the last line was focused</returns>
        protected override bool TryLoopToLastLine()
        {
            IItemProvider itemProvider = ItemProvider;

            if (itemProvider == null)
            {
                return(base.TryLoopToFirstLine());
            }
            int numItems = itemProvider.NumItems;

            if (numItems == 0)
            {
                return(false);
            }
            FrameworkElement currentElement = GetFocusedElementOrChild();

            if (currentElement == null)
            {
                return(false);
            }
            IList <LineMeasurement> lines = new List <LineMeasurement>(_arrangedLines);

            if (lines.Count == 0)
            {
                return(false);
            }
            var firstLine = lines[0];

            //check if first arranged line is actual first line
            if (firstLine.StartIndex != 0)
            {
                return(false);
            }
            for (int childIndex = firstLine.StartIndex; childIndex <= firstLine.EndIndex; childIndex++)
            {
                FrameworkElement item = GetItem(childIndex, itemProvider, false);
                if (item != null && InVisualPath(item, currentElement))
                {
                    //item on first line has focuse
                    int lineLength = firstLine.EndIndex - firstLine.StartIndex + 1;
                    //calculate number of items on last line, may be fewer than first line
                    int remainder = itemProvider.NumItems % lineLength;
                    if (remainder == 0)
                    {
                        remainder = lineLength;
                    }
                    //set focus to item in same position or last item if less
                    int itemIndex = numItems - remainder + childIndex;
                    CalcHelper.Bound(ref itemIndex, 0, numItems - 1);
                    item = GetItem(itemIndex, itemProvider, false);
                    if (item != null)
                    {
                        item.SetFocusPrio = SetFocusPriority.Default;
                    }
                    SetScrollIndex(int.MaxValue, false);
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> modified Macauley duration for a security with an assumed par value of $100.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 5 - 6 items: settlement, maturity, coupon, yld, frequency, [basis].
        /// </para>
        /// <para>
        /// Settlement is the security's settlement date.
        /// The security settlement date is the date after the issue date when the security is traded to the buyer.
        /// </para>
        /// <para>
        /// Maturity is the security's maturity date.
        /// The maturity date is the date when the security expires.
        /// </para>
        /// <para>
        /// Coupon is the security's annual coupon rate.
        /// </para>
        /// <para>
        /// Yld is the security's annual yield.
        /// </para>
        /// <para>
        /// Frequency is the number of coupon payments per year.
        /// For annual payments, frequency = 1; for semiannual, frequency = 2; for quarterly, frequency = 4.
        /// </para>
        /// <para>
        /// Basis is the type of day count basis to use.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            DateTime time   = CalcConvert.ToDateTime(args[0]);
            DateTime time2  = CalcConvert.ToDateTime(args[1]);
            double   fCoup  = CalcConvert.ToDouble(args[2]);
            double   fYield = CalcConvert.ToDouble(args[3]);
            int      freq   = CalcConvert.ToInt(args[4]);
            int      nBase  = CalcHelper.ArgumentExists(args, 5) ? CalcConvert.ToInt(args[5]) : 0;

            if ((nBase < 0) || (nBase > 4))
            {
                return(CalcErrors.Number);
            }
            if (((freq != 1) && (freq != 2)) && (freq != 4))
            {
                return(CalcErrors.Number);
            }
            if (DateTime.Compare(time, time2) > 0)
            {
                return(CalcErrors.Number);
            }
            double fNumOfCoups = FinancialHelper.coupnum(time, time2, freq);

            return((double)this.get_mduration(time, time2, fCoup, fYield, freq, nBase, fNumOfCoups));
        }
Exemplo n.º 24
0
        /// <summary>
        /// Summarizes the extends of the given <paramref name="lines"/> in non-orientation direction.
        /// </summary>
        /// <param name="lines">Lines to summarize.</param>
        /// <param name="startIndex">Index of the first line, inclusive.</param>
        /// <param name="endIndex">Index of the last line, exclusive.</param>
        /// <returns></returns>
        protected float SumActualLineExtendsInNonOrientationDirection(IList <LineMeasurement> lines, int startIndex, int endIndex)
        {
            int numLines = lines.Count;

            CalcHelper.Bound(ref startIndex, 0, numLines - 1);
            CalcHelper.Bound(ref endIndex, 0, numLines); // End index is exclusive
            if (startIndex == endIndex || numLines == 0)
            {
                return(0);
            }
            bool invert = startIndex > endIndex;

            if (invert)
            {
                int tmp = startIndex;
                startIndex = endIndex;
                endIndex   = tmp;
            }
            float result = 0;

            for (int i = startIndex; i < endIndex; i++)
            {
                result += lines[i].TotalExtendsInNonOrientationDirection;
            }
            return(invert ? -result : result);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Returns a reference to a range that is a specified number of
        /// rows and columns from a cell or range of cells.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 3 - 5 items: reference, rows, cols, [height], [width].
        /// </para>
        /// <para>
        /// Reference is the reference from which you want to base the offset.
        /// </para>
        /// <para>
        /// Rows is the number of rows, up or down, that you want the upper-left
        /// cell to refer to.
        /// </para>
        /// <para>
        /// Cols is the number of columns, to the left or right, that you want
        /// the upper-left cell of the result to refer to.
        /// </para>
        /// <para>
        /// [Height] is the height, in number of rows, that you want the returned
        /// reference to be. Height must be a positive number.
        /// </para>
        /// <para>
        /// [Width] is the width, in number of columns, that you want the returned
        /// reference to be. Width must be a positive number.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:Dt.CalcEngine.CalcReference" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            CalcReference reference = args[0] as CalcReference;

            if ((reference == null) || (reference.RangeCount != 1))
            {
                return(CalcErrors.Value);
            }
            int           num         = CalcConvert.ToInt(args[1]);
            int           num2        = CalcConvert.ToInt(args[2]);
            int           rowCount    = CalcHelper.ArgumentExists(args, 3) ? CalcConvert.ToInt(args[3]) : reference.GetRowCount(0);
            int           columnCount = CalcHelper.ArgumentExists(args, 4) ? CalcConvert.ToInt(args[4]) : reference.GetColumnCount(0);
            CalcReference source      = reference.GetSource();
            int           row         = reference.GetRow(0) + num;
            int           column      = reference.GetColumn(0) + num2;

            if ((rowCount > 0) && (columnCount > 0))
            {
                if ((row < source.GetRow(0)) || ((source.GetRow(0) + source.GetRowCount(0)) < (row + rowCount)))
                {
                    return(CalcErrors.Reference);
                }
                if ((column >= source.GetColumn(0)) && ((source.GetColumn(0) + source.GetColumnCount(0)) >= (column + columnCount)))
                {
                    return(new ConcreteReference(source, row, column, rowCount, columnCount));
                }
            }
            return(CalcErrors.Reference);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> number of periods for an investment based on periodic, constant payments and a constant interest rate.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 3 - 5 items: rate, pmt, pv, [fv], [type].
        /// </para>
        /// <para>
        /// Rate is the interest rate per period.
        /// </para>
        /// <para>
        /// Pmt is the payment made each period; it cannot change over the life of the annuity.
        /// Typically, pmt contains principal and interest but no other fees or taxes.
        /// </para>
        /// <para>
        /// Pv is the present value, or the lump-sum amount that a series of future payments is worth right now.
        /// </para>
        /// <para>
        /// Fv is the future value, or a cash balance you want to attain after the last payment is made.
        /// If fv is omitted, it is assumed to be 0 (the future value of a loan, for example, is 0).
        /// </para>
        /// <para>
        /// Type is the number 0 or 1 and indicates when payments are due.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            double num  = CalcConvert.ToDouble(args[0]);
            double num2 = CalcConvert.ToDouble(args[1]);
            double num3 = CalcConvert.ToDouble(args[2]);
            double num4 = CalcHelper.ArgumentExists(args, 3) ? CalcConvert.ToDouble(args[3]) : 0.0;
            double num5 = CalcHelper.ArgumentExists(args, 4) ? CalcConvert.ToDouble(args[4]) : 0.0;

            if (num5 != 0.0)
            {
                num5 = 1.0;
            }
            if (num == 0.0)
            {
                if (num2 == 0.0)
                {
                    return(CalcErrors.DivideByZero);
                }
                return(CalcConvert.ToResult(-(num3 + num4) / num2));
            }
            if (num <= -1.0)
            {
                return(CalcErrors.Number);
            }
            return(CalcConvert.ToResult(Math.Log(((num2 * (1.0 + (num * num5))) - (num4 * num)) / ((num3 * num) + (num2 * (1.0 + (num * num5))))) / Math.Log(1.0 + num)));
        }
Exemplo n.º 27
0
        /// <summary>
        /// Returns the <see cref="T:System.String" /> number converted from octal to binary.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 - 2 items: number, [places].
        /// </para>
        /// <para>
        /// Number is the octal number you want to convert.
        /// Number may not contain more than 10 characters.
        /// The most significant bit of number is the sign bit.
        /// The remaining 29 bits are magnitude bits.
        /// Negative numbers are represented using two's-complement notation.
        /// </para>
        /// <para>
        /// Places is the number of characters to use.
        /// If places is omitted, OCT2BIN uses the minimum number of characters necessary.
        /// Places is useful for padding the return value with leading 0s (zeros).
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.String" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            int num3;

            base.CheckArgumentsLength(args);
            string s   = CalcConvert.ToString(args[0]);
            int    num = CalcHelper.ArgumentExists(args, 1) ? CalcConvert.ToInt(args[1]) : 1;

            if (10 < s.Length)
            {
                return(CalcErrors.Number);
            }
            if ((num < 1) || (10 < num))
            {
                return(CalcErrors.Number);
            }
            long number = EngineeringHelper.StringToLong(s, 8, out num3);

            if (num3 < s.Length)
            {
                return(CalcErrors.Number);
            }
            if ((number < -512L) || (0x1ffL < number))
            {
                return(CalcErrors.Number);
            }
            string str2 = EngineeringHelper.LongToString(number, 2L, (long)num);

            if (((0L <= number) && (num < str2.Length)) && CalcHelper.ArgumentExists(args, 1))
            {
                return(CalcErrors.Number);
            }
            return(str2);
        }
Exemplo n.º 28
0
 /// <summary>
 /// Creates destruction specific particles around an area.
 /// </summary>
 /// <param name="rect"></param>
 private static void CreateDestructionParticles(Rectangle rect)
 {
     for (var i = 0; i < 5; i++)
     {
         ParticleSystem.Add(ParticleType.Smoke, CalcHelper.GetRandXAndY(rect), new Vector2(TMBAW_Game.Random.Next(-10, 10) / 10f, TMBAW_Game.Random.Next(-10, 10) / 10f), Color.White);
     }
 }
Exemplo n.º 29
0
        private void tsmPaymentsCreate_Click(object sender, EventArgs e)
        {
            bool isPeriodFilled = false;

            using (var context = new DataClassesDataContext())
            {
                var period = GetPeriod(context);
                isPeriodFilled = period.PaymentEmployees.Count > 0;
            }

            if (!isPeriodFilled || MessageBox.Show(this, "Начисления по периоду уже сформированны.\r\nВы хотите попробовать добавить сотрудников,\r\nотсутствующих в назначении?", "Подтверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                int added = 0;
                using (var context = new DataClassesDataContext())
                {
                    added = CalcHelper.MakePayments(context, ShowYear, ShowMonth);
                }

                FillGrid();

                if (added > 0)
                {
                    MessageBox.Show(this, string.Format("Добавленно сотрудников: {0}", added), "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(this, "Сотрудников без назначений не найденно", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Exemplo n.º 30
0
        protected void AddFocusedElementRange(IList <FrameworkElement> availableElements, RectangleF?startingRect,
                                              int firstElementIndex, int lastElementIndex, int elementsBefore, int elementsAfter, ICollection <FrameworkElement> outElements)
        {
            int numItems = availableElements.Count;

            if (numItems == 0)
            {
                return;
            }
            CalcHelper.Bound(ref firstElementIndex, 0, numItems - 1);
            CalcHelper.Bound(ref lastElementIndex, 0, numItems - 1);
            if (elementsBefore > 0)
            {
                // Find children before the first index which have focusable elements.
                int formerNumElements = outElements.Count;
                for (int i = firstElementIndex - 1; i >= 0; i--)
                {
                    FrameworkElement fe = availableElements[i];
                    fe.AddPotentialFocusableElements(startingRect, outElements);
                    if (formerNumElements == outElements.Count)
                    {
                        continue;
                    }
                    // Found focusable elements
                    elementsBefore--;
                    if (elementsBefore == 0)
                    {
                        break;
                    }
                    formerNumElements = outElements.Count;
                }
            }
            for (int i = firstElementIndex; i <= lastElementIndex; i++)
            {
                FrameworkElement fe = availableElements[i];
                fe.AddPotentialFocusableElements(startingRect, outElements);
            }
            if (elementsAfter > 0)
            {
                // Find children after the last index which have focusable elements.
                int formerNumElements = outElements.Count;
                for (int i = lastElementIndex + 1; i < availableElements.Count; i++)
                {
                    FrameworkElement fe = availableElements[i];
                    fe.AddPotentialFocusableElements(startingRect, outElements);
                    if (formerNumElements == outElements.Count)
                    {
                        continue;
                    }
                    // Found focusable elements
                    elementsAfter--;
                    if (elementsAfter == 0)
                    {
                        break;
                    }
                    formerNumElements = outElements.Count;
                }
            }
        }