Exemple #1
0
        //-> SelectByID
        public async Task <AccountViewDTO> SelectByID(int id)
        {
            var account = await db.tblAccounts.FirstOrDefaultAsync(a => a.acct_Deleted == null && a.acct_AccountID == id);

            if (account == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, "NotFound");
            }

            var accountView = DoubleHelper.TwoPrecision(MappingHelper.MapDBClassToDTO <tblAccount, AccountViewDTO>(account));

            accountView.statusCaption = SelectionHelper.AccountStatusCaption(account.acct_Status);
            accountView.documents     = DocumentHelper.GetDocuments(db, ConstantHelper.TABLE_ACCOUNT_ID, account.acct_AccountID);
            return(accountView);
        }
        public static bool operator >(AnimationRate t1, AnimationRate t2)
        {
            if (t1.HasDuration && t2.HasDuration)
            {
                return(t1._duration > t2._duration);
            }

            if (t1.HasSpeed && t2.HasSpeed)
            {
                return((t1._speed > t2._speed) && !DoubleHelper.AreVirtuallyEqual(t1._speed, t2._speed));
            }

            // arbitrary: assume a Speed is greater than a Duration
            return(t1.HasSpeed);
        }
Exemple #3
0
        private static object CoerceEndAngleValue(DependencyObject d, object value)
        {
            // keep EndAngle in sync with Slice and SweepDirection
            Pie pie = ( Pie )d;

            if (pie.IsUpdatingSlice || pie.IsUpdatingSweepDirection ||
                (pie.IsUpdatingStartAngle && pie.Mode == PieMode.Slice))
            {
                double newValue = pie.StartAngle + ((pie.SweepDirection == SweepDirection.Clockwise) ? 1.0 : -1.0) * pie.Slice * 360;
                if (!DoubleHelper.AreVirtuallyEqual(( double )value, newValue))
                {
                    value = newValue;
                }
            }
            return(value);
        }
Exemple #4
0
        private static object CoerceSliceValue(DependencyObject d, object value)
        {
            // keep Slice in sync with EndAngle, StartAngle, and SweepDirection
            Pie pie = ( Pie )d;

            if (pie.IsUpdatingEndAngle || pie.IsUpdatingStartAngle || pie.IsUpdatingSweepDirection)
            {
                double slice    = Math.Max(-360.0, Math.Min(360.0, (pie.EndAngle - pie.StartAngle))) / ((pie.SweepDirection == SweepDirection.Clockwise) ? 360.0 : -360.0);
                double newValue = DoubleHelper.AreVirtuallyEqual(slice, 0) ? 0 : (slice < 0) ? slice + 1 : slice;
                if (!DoubleHelper.AreVirtuallyEqual(( double )value, newValue))
                {
                    value = newValue;
                }
            }
            return(value);
        }
        private void UpdateSizeFromRadius()
        {
            if (this.FrameType == Toolkit.FrameType.Circle)
            {
                double newSize = Radius * 2;
                if (!DoubleHelper.AreVirtuallyEqual(Width, newSize))
                {
                    Width = newSize;
                }

                if (!DoubleHelper.AreVirtuallyEqual(Height, newSize))
                {
                    Height = newSize;
                }
            }
        }
        public void Map_CalculatesCorrectSegmentWidth(Tuple <double, double, double> testData)
        {
            var area          = testData.Item1;
            var depth         = testData.Item2;
            var expectedWidth = testData.Item3;

            var panelItem = _gaugingSummaryItem.PanelItems.First();

            panelItem.Area  = area;
            panelItem.Depth = depth;

            var result        = _verticalMapper.Map(_gaugingSummaryItem, _deploymentMethod);
            var firstVertical = result.First();

            Assert.That(DoubleHelper.AreEqual(firstVertical.Segment.Width, expectedWidth));
        }
Exemple #7
0
        public override double ConvertToPercent(object value)
        {
            if (value == null)
            {
                return(double.NaN);
            }
            this.RecalculateIfEmpty();
            Range <double> fromRange = new Range <double>(this.ActualMinimum, this.ActualMaximum);
            double         num       = Convert.ToDouble(value, (IFormatProvider)CultureInfo.InvariantCulture);

            if (DoubleHelper.LessWithPrecision(num, fromRange.Minimum) || DoubleHelper.GreaterWithPrecision(num, fromRange.Maximum))
            {
                return(double.NaN);
            }
            return(RangeHelper.Project(fromRange, num, Scale.PercentRange));
        }
        private void AddReadingComments(Reading reading, double?src, string srcAction, params string[] otherComments)
        {
            var comments = otherComments
                           .Concat(new []
            {
                src.HasValue&& !DoubleHelper.AreSame(src, 0.0) ? $"SRC: {src:F3}" : null,
                srcAction,
            })
                           .Where(s => !string.IsNullOrWhiteSpace(s))
                           .ToList();

            if (comments.Any())
            {
                reading.Comments = string.Join("\r\n", comments);
            }
        }
        public static bool ScrollLeastAmount(Rect physViewRect, Rect itemRect, out Vector newPhysOffset)
        {
            bool scrollNeeded = false;

            newPhysOffset = new Vector();

            if (physViewRect.Contains(itemRect) == false)
            {
                // Check if child is inside the view horizontially.
                if (itemRect.Left > physViewRect.Left && itemRect.Right < physViewRect.Right ||
                    DoubleHelper.AreVirtuallyEqual(itemRect.Left, physViewRect.Left) == true)
                {
                    newPhysOffset.X = itemRect.Left;
                }
                // Child is to the left of the view or is it bigger than the view
                else if (itemRect.Left < physViewRect.Left || itemRect.Width > physViewRect.Width)
                {
                    newPhysOffset.X = itemRect.Left;
                }
                // Child is to the right of the view
                else
                {
                    newPhysOffset.X = Math.Max(0, physViewRect.Left + (itemRect.Right - physViewRect.Right));
                }

                // Check if child is inside the view vertically.
                if (itemRect.Top > physViewRect.Top && itemRect.Bottom < physViewRect.Bottom ||
                    DoubleHelper.AreVirtuallyEqual(itemRect.Top, physViewRect.Top) == true)
                {
                    newPhysOffset.Y = itemRect.Top;
                }
                // Child is the above the view or is it bigger than the view
                else if (itemRect.Top < physViewRect.Top || itemRect.Height > physViewRect.Height)
                {
                    newPhysOffset.Y = itemRect.Top;
                }
                // Child is below the view
                else
                {
                    newPhysOffset.Y = Math.Max(0, physViewRect.Top + (itemRect.Bottom - physViewRect.Bottom));
                }

                scrollNeeded = true;
            }

            return(scrollNeeded);
        }
Exemple #10
0
        public static ValueRange CheckValue(double value, ValueRange[] ranges)
        {
            if (double.IsNaN(value) || DoubleHelper.Equals(value, 0.0d, 0.0000000001d) || ranges == null)
            {
                return(null);
            }

            foreach (var bounds in ranges)
            {
                if (value >= bounds.Min && value <= bounds.Max)
                {
                    return(bounds);
                }
            }

            return(null);
        }
Exemple #11
0
        /**
         * Gets the binary data for writing to the output file
         *
         * @return the binary data
         */
        public override byte[] getData()
        {
            DoubleHelper.getIEEEBytes(iterationValue, data, 0);

            /*    long val = Double.doubleToLongBits(iterationValue);
             * data[0] = (byte) (val & 0xff);
             * data[1] = (byte) ((val & 0xff00) >> 8);
             * data[2] = (byte) ((val & 0xff0000) >> 16);
             * data[3] = (byte) ((val & 0xff000000) >> 24);
             * data[4] = (byte) ((val & 0xff00000000L) >> 32);
             * data[5] = (byte) ((val & 0xff0000000000L) >> 40);
             * data[6] = (byte) ((val & 0xff000000000000L) >> 48);
             * data[7] = (byte) ((val & 0xff00000000000000L) >> 56) ;
             */

            return(data);
        }
        private static Expression <Func <TModel, bool> > ToDoubleValueExpression <TModel>(FilterItemModel filterItem, bool isNullable)
            where TModel : class
        {
            var nullableFilterValue = DoubleHelper.ToDoubleOrNull(filterItem.Value);

            if (!nullableFilterValue.HasValue)
            {
                throw new ArgumentException($"{filterItem.Value} is not of type {typeof(double)}.");
            }

            var filterValue = nullableFilterValue.Value;

            if (isNullable)
            {
                var entityParamSelector = ReflectionHelper.MemberSelector <TModel, double?>(filterItem.Column);
                if (filterItem.Filter == FilterType.In)
                {
                    var result = filterItem.CollectionExpression(entityParamSelector, DoubleHelper.ToDoubleOrNull);
                    if (result != null)
                    {
                        return(result);
                    }
                }

                var expression = FilterExpressionHelper.GetNullableExpression(filterItem.Filter, filterValue);

                return(entityParamSelector.CombineSelectorParamExpression(expression));
            }
            else
            {
                var entityParamSelector = ReflectionHelper.MemberSelector <TModel, double>(filterItem.Column);
                if (filterItem.Filter == FilterType.In)
                {
                    var result = filterItem.CollectionExpression(entityParamSelector, DoubleHelper.ToDouble);
                    if (result != null)
                    {
                        return(result);
                    }
                }

                var expression = FilterExpressionHelper.GetExpression(filterItem.Filter, filterValue);

                return(entityParamSelector.CombineSelectorParamExpression(expression));
            }
        }
Exemple #13
0
        public override double ConvertToPercent(object value)
        {
            if (value == null)
            {
                return(double.NaN);
            }
            double         num        = Convert.ToDouble(value, (IFormatProvider)CultureInfo.InvariantCulture);
            Range <double> fromRange  = new Range <double>(this.ActualMinimum, this.ActualMaximum);
            double         precision1 = DoubleHelper.GetPrecision(num, fromRange.Minimum, fromRange.Maximum);

            if (DoubleHelper.LessWithPrecision(num, fromRange.Minimum, precision1) || DoubleHelper.GreaterWithPrecision(num, fromRange.Maximum, precision1))
            {
                return(double.NaN);
            }
            double precision2 = DoubleHelper.GetPrecision(1, new double[0]);

            return(DoubleHelper.RoundWithPrecision(RangeHelper.Project(fromRange, num, Scale.PercentRange), precision2));
        }
        /**
         * Constructs this object from the raw data
         *
         * @param t the raw data
         * @param fr the formatting record
         * @param es the external sheet
         * @param nt the name table
         * @param si the sheet
         */
        public NumberFormulaRecord(Record t, FormattingRecords fr,
                                   ExternalSheet es, WorkbookMethods nt,
                                   SheetImpl si)
            : base(t, fr, si)
        {
            externalSheet = es;
            nameTable     = nt;
            data          = getRecord().getData();

            format = fr.getNumberFormat(getXFIndex());

            if (format == null)
            {
                format = defaultFormat;
            }

            value = DoubleHelper.getIEEEDouble(data, 6);
        }
        public static void SetValueWithAnimation(this DataPoint dataPoint, DependencyProperty dp, string propertyName, double value)
        {
            double num = (double)dataPoint.GetValue(dp);

            if (num == value)
            {
                return;
            }
            Series series = dataPoint.Series;

            if (series == null || series.ChartArea == null || (DoubleHelper.IsNaN(num) || DoubleHelper.IsNaN(value)))
            {
                dataPoint.SetValue(dp, (object)value);
            }
            else
            {
                DependencyPropertyAnimationHelper.BeginAnimation(series.ChartArea, propertyName, (object)num, (object)value, (Action <object, object>)((current, next) => dataPoint.SetValue(dp, next)), dataPoint.Storyboards, series.ActualTransitionDuration, series.ActualTransitionEasingFunction);
            }
        }
Exemple #16
0
        private static object CoerceSweepDirectionValue(DependencyObject d, object value)
        {
            // keep SweepDirection in sync with EndAngle and StartAngle
            Pie pie = ( Pie )d;

            if (pie.IsUpdatingEndAngle || pie.IsUpdatingStartAngle || pie.IsUpdatingMode)
            {
                if (DoubleHelper.AreVirtuallyEqual(pie.StartAngle, pie.EndAngle))
                {
                    // if the values are equal, use previously coerced value
                    value = pie.SweepDirection;
                }
                else
                {
                    value = (pie.EndAngle < pie.StartAngle) ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
                }
            }
            return(value);
        }
        public void Map_CalculatesCorrectTotalDischargePortionValues(Tuple <double[], double[]> testData)
        {
            var inputDischargeValues = testData.Item1;
            var panelItems           = _gaugingSummaryItem.PanelItems.ToList();

            for (var i = 0; i < panelItems.Count; i++)
            {
                panelItems[i].Flow = inputDischargeValues[i];
            }

            var result = _verticalMapper.Map(_gaugingSummaryItem, _deploymentMethod);

            var expectedTotalDischargePortionValues = testData.Item2;

            for (var i = 0; i < result.Count; i++)
            {
                Assert.That(DoubleHelper.AreEqual(result[i].Segment.TotalDischargePortion,
                                                  expectedTotalDischargePortionValues[i]));
            }
        }
Exemple #18
0
        private void ZoomPlotArea(bool isZoomIn, double xCenterValue, double yCenterValue)
        {
            double delta = isZoomIn ? 1.2 : 5.0 / 6.0;

            foreach (Axis axis in (Collection <Axis>) this.Axes)
            {
                if (axis.ActualIsZoomEnabled)
                {
                    if (this.IsHorizontalAxis(axis))
                    {
                        axis.Scale.ZoomBy(xCenterValue, delta);
                    }
                    else
                    {
                        axis.Scale.ZoomBy(yCenterValue, delta);
                    }
                    axis.ShowScrollZoomBar = DoubleHelper.GreaterWithPrecision(axis.Scale.ActualZoom, 1.0);
                }
            }
        }
Exemple #19
0
        public static Triangle CreateTriangleFromConsole()
        {
            double a, b, c;

            Console.WriteLine("Давайте создадим треугольник! Введите длинны сторон треугольника!");
            while (true)
            {
                a = DoubleHelper.ReadDoubleFormConsole("A = ", true);
                b = DoubleHelper.ReadDoubleFormConsole("B = ", true);
                c = DoubleHelper.ReadDoubleFormConsole("C = ", true);
                if (CheckingExistenceTriangle(a, b, c))
                {
                    break;
                }
                Console.WriteLine(
                    "К сожалению треугольника с такими сторонами не существует :( Попробуйте заново! (Сумма двух сторон больше третьей)");
            }

            return(new Triangle(a, b, c));
        }
        //-> SelectByID
        public async Task <CheckLoanRequestViewDTO> SelectByID(int id)
        {
            var accountHandler   = new AccountHandler();
            var checkLoanRequest = new CheckLoanRequestViewDTO();

            checkLoanRequest.account = DoubleHelper.TwoPrecision(await accountHandler.SelectByID(id));

            var loanRequest = await db.tblLoanRequests.FirstOrDefaultAsync(l =>
                                                                           (l.loan_Status.ToLower() != "approved" && l.loan_Status.ToLower() != "rejected") &&
                                                                           l.loan_Deleted == null && l.loan_AccountID == id);

            if (loanRequest == null)
            {
                loanRequest = new tblLoanRequest();
            }

            checkLoanRequest.loanRequest = DoubleHelper.TwoPrecision(MappingHelper.MapDBClassToDTO <tblLoanRequest, LoanRequestViewDTO>(loanRequest));
            //checkLoanRequest.loanRequest = MappingHelper.MapDBClassToDTO<tblLoanRequest, LoanRequestViewDTO>(loanRequest);
            return(DoubleHelper.TwoPrecision(checkLoanRequest));
        }
Exemple #21
0
        public static Employee AddNewEployeeFromConsole()
        {
            Console.Write("Добавить нового сотрудника.\nВведите фамилию: ");
            var surname = Console.ReadLine();

            Console.Write("Введите имя: ");
            var name = Console.ReadLine();

            Console.Write("Введите отчество: ");
            var patronymic = Console.ReadLine();

            Console.WriteLine("Теперь разберемся с датой рождения!");
            var birthday = DateHelper.ReadDateOfBirthdayFormConsole();

            Console.Write("Занимаемая должность: ");
            var position   = Console.ReadLine();
            var experience = DoubleHelper.ReadDoubleFormConsole("Стаж работы: ", true);

            return(new Employee(surname, name, patronymic, birthday, position, experience));
        }
Exemple #22
0
        /// <summary> Constructor which creates this object from the binary data
        ///
        /// </summary>
        /// <param name="t">the record
        /// </param>
        internal SetupRecord(Record t) : base(NExcel.Biff.Type.SETUP)
        {
            data = t.Data;

            paperSize   = IntegerHelper.getInt(data[0], data[1]);
            scaleFactor = IntegerHelper.getInt(data[2], data[3]);
            pageStart   = IntegerHelper.getInt(data[4], data[5]);
            fitWidth    = IntegerHelper.getInt(data[6], data[7]);
            fitHeight   = IntegerHelper.getInt(data[8], data[9]);
            horizontalPrintResolution = IntegerHelper.getInt(data[12], data[13]);
            verticalPrintResolution   = IntegerHelper.getInt(data[14], data[15]);
            copies = IntegerHelper.getInt(data[32], data[33]);

            headerMargin = DoubleHelper.getIEEEDouble(data, 16);
            footerMargin = DoubleHelper.getIEEEDouble(data, 24);



            int grbit = IntegerHelper.getInt(data[10], data[11]);

            portraitOrientation = ((grbit & 0x02) != 0);
        }
        private void ParseValue(string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                string[] parts = value.Split('-');

                if (parts.Length == 2)
                {
                    double val;

                    if (DoubleHelper.TryParseCultureInvariant(parts[0], out val))
                    {
                        _width = val;
                    }

                    if (DoubleHelper.TryParseCultureInvariant(parts[1], out val))
                    {
                        _height = val;
                    }
                }
            }
        }
Exemple #24
0
        //
        // Convert a Number to a double.
        //
        internal static bool NumberBufferToDouble(ref NumberBuffer number, out double value)
        {
            double d = NumberToDouble(ref number);

            uint  e = DoubleHelper.Exponent(d);
            ulong m = DoubleHelper.Mantissa(d);

            if (e == 0x7FF)
            {
                value = default;
                return(false);
            }

            if (e == 0 && m == 0)
            {
                d = 0;
            }

            value = d;

            return(true);
        }
Exemple #25
0
        private static int GetCentreX(int canvasWidth, int factoredRadius, bool lefthand)
        {
            var halfCanvasWidth = (int)DoubleHelper.GetMax((int)Math.Floor(canvasWidth * 0.5), 1);

            if (factoredRadius >= halfCanvasWidth)
            {
                return(lefthand
                    ? (int)Math.Floor(canvasWidth * 0.45) - factoredRadius
                    : (int)Math.Floor(canvasWidth * 0.55) + factoredRadius);
            }

            if (factoredRadius * 2 < halfCanvasWidth)
            {
                return(lefthand
                    ? (int)Math.Floor(canvasWidth * 0.25)
                    : (int)Math.Floor(canvasWidth * 0.75));
            }

            return(lefthand
                ? 0
                : canvasWidth);
        }
Exemple #26
0
        /**
         * Error formula specific exception handling.  Can't really create
         * a formula (as it will look for a cell of that name, so just
         * create a STRING record containing the contents
         *
         * @return the bodged data
         */
        public override byte[] handleFormulaException()
        {
            byte[] expressiondata = null;
            byte[] celldata       = base.getCellData();

            // Generate an appropriate dummy formula
            WritableWorkbookImpl w      = getSheet().getWorkbook();
            FormulaParser        parser = new FormulaParser(getValue().ToString(), w, w, w.getSettings());

            // Get the bytes for the dummy formula
            try
            {
                parser.parse();
            }
            catch (FormulaException e2)
            {
                //logger.warn(e2.Message);
            }
            byte[] formulaBytes = parser.getBytes();
            expressiondata = new byte[formulaBytes.Length + 16];
            IntegerHelper.getTwoBytes(formulaBytes.Length, expressiondata, 14);
            System.Array.Copy(formulaBytes, 0, expressiondata, 16,
                              formulaBytes.Length);

            // Set the recalculate on load bit
            expressiondata[8] |= 0x02;

            byte[] data = new byte[celldata.Length +
                                   expressiondata.Length];
            System.Array.Copy(celldata, 0, data, 0, celldata.Length);
            System.Array.Copy(expressiondata, 0, data,
                              celldata.Length, expressiondata.Length);

            // Store the value in the formula
            DoubleHelper.getIEEEBytes(getValue(), data, 6);

            return(data);
        }
Exemple #27
0
 /// <summary>
 ///     オプション項目を初期化する
 /// </summary>
 private void InitOptionItems()
 {
     if (Researches.DateMode == ResearchDateMode.Historical)
     {
         historicalRadioButton.Checked = true;
         yearNumericUpDown.Enabled     = false;
         monthNumericUpDown.Enabled    = false;
         dayNumericUpDown.Enabled      = false;
     }
     else
     {
         specifiedRadioButton.Checked = true;
         yearNumericUpDown.Enabled    = true;
         monthNumericUpDown.Enabled   = true;
         dayNumericUpDown.Enabled     = true;
     }
     yearNumericUpDown.Value    = Researches.SpecifiedDate.Year;
     monthNumericUpDown.Value   = Researches.SpecifiedDate.Month;
     dayNumericUpDown.Value     = Researches.SpecifiedDate.Day;
     rocketNumericUpDown.Value  = Researches.RocketTestingSites;
     nuclearNumericUpDown.Value = Researches.NuclearReactors;
     blueprintCheckBox.Checked  = Researches.Blueprint;
     modifierTextBox.Text       = DoubleHelper.ToString(Researches.Modifier);
 }
Exemple #28
0
        public void Serialize_ValueIsNull_ReturnsEmptyString()
        {
            var result = DoubleHelper.Serialize(null);

            Assert.That(result, Is.Null);
        }
Exemple #29
0
 internal bool IsSizeEmptyOrUndefined(Size size)
 {
     return(DoubleHelper.IsNaN(size.Width) || DoubleHelper.IsNaN(size.Height) || size.IsEmpty);
 }
Exemple #30
0
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) // From string to double
 {
     return((value != null) ? DoubleHelper.ToDouble(value.ToString()) : null);
 }