Beispiel #1
0
        public static double NAMoneyFormatD(this double n, Boolean b) //Method to avoid discrepancies
        {
            double money = n * 100;

            if (b == true)
            {
                if (money < 0)
                {
                    money *= -1;
                    decimal d = (Decimal.Ceiling((decimal)money)) / 100;
                    return((double)d);
                }
                else
                {
                    decimal d = (Decimal.Ceiling((decimal)money)) / 100;
                    return((double)d);
                }
            }
            else
            {
                if (money < 0)
                {
                    money *= -1;
                    decimal d = (Decimal.Ceiling((decimal)money)) / 100;
                    return((double)d);
                }
                else
                {
                    decimal d = (Decimal.Ceiling((decimal)money)) / 100;
                    return((double)d);
                }
            }
        }
Beispiel #2
0
        public static string NAMoneyFormat(this double n, Boolean b)
        {
            double money = n * 100;

            if (b == true)
            {
                if (money < 0)
                {
                    money *= -1;
                    string str = string.Format("{0:C}", (Decimal.Ceiling((decimal)money)) / 100); //rounds number
                    return(str);
                }
                else
                {
                    string str = string.Format("{0:C}", (Decimal.Ceiling((decimal)money)) / 100); //rounds number
                    return(str);
                }
            }
            else
            {
                if (money < 0)
                {
                    money *= -1;
                    string str = string.Format("{0:C}", (Decimal.Ceiling((decimal)money)) / 100); //rounds number
                    return(str);
                }
                else
                {
                    string str = string.Format("{0:C}", (Decimal.Ceiling((decimal)money)) / 100); //rounds number
                    return(str);
                }
            }
        }
Beispiel #3
0
        public static double ToNAMoneyFormatD(this double n, Boolean tf)  //Added this extension method in order to be able to round nicely all the numbers going in the system so there isn't any discrepancies
        {
            double theMoney = n * 100;

            if (tf == true)
            {
                if (theMoney < 0)
                {
                    theMoney *= -1;
                    decimal d = (Decimal.Ceiling((decimal)theMoney)) / 100; //Rounds the number accordingly
                    return((double)d);
                }
                else
                {
                    decimal d = (Decimal.Ceiling((decimal)theMoney)) / 100;  //Rounds the number accordingly
                    return((double)d);
                }
            }
            else
            {
                if (theMoney < 0)
                {
                    theMoney *= -1;
                    decimal d = (Decimal.Floor((decimal)theMoney)) / 100; //Rounds the number downwards
                    return((double)d);
                }
                else
                {
                    decimal d = (Decimal.Floor((decimal)theMoney)) / 100; //Rounds the number downwards
                    return((double)d);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// エネルギー値を指定した範囲に制限したROISpectraを返します。
        /// </summary>
        /// <param name="pitch"></param>
        /// <returns></returns>
        public ROISpectra Restrict(decimal start, decimal stop)
        {
            var original_start = Parameter.Start;
            var original_stop  = Parameter.Stop;
            var step           = Parameter.Step;

            if (start >= original_start && stop <= original_stop && start <= stop)
            {
                var start_index = Convert.ToInt32(Decimal.Ceiling((start - original_start) / step));
                var stop_index  = Convert.ToInt32(Decimal.Floor((stop - original_start) / step));

                return(new ROISpectra
                {
                    Name = this.Name,
                    Data = this.Data.Select(data => data.GetSubData(start_index, stop_index)).ToArray(),
                    Parameter = new ScanParameter
                    {
                        Start = original_start + start_index * step,
                        Stop = original_start + stop_index * step,
                        Step = step,
                        Current = Parameter.Current,
                        Dwell = Parameter.Dwell,
                        Tilt = Parameter.Tilt
                    }
                });
            }
            else
            {
                throw new ArgumentException("もとのスペクトルの範囲内でないといけません。");
            }
        }
Beispiel #5
0
        static void DecimalDataTypes()
        {
            decimal totalAmount;

            totalAmount = 45.61M;
            decimal totalDollars, totalCents;

            totalDollars = decimal.Truncate(totalAmount);
            totalCents   = totalAmount - totalDollars;

            Console.WriteLine("The restaurant bill is {0:C}", totalAmount);
            Console.WriteLine("You pay the {0:C}, and I'll pay the {1:C}", totalDollars, totalCents);
            Console.WriteLine();

            totalAmount = 45.674586748657M;
            Console.WriteLine("The total amount is {0}", totalAmount);
            Console.WriteLine("Rounded to 0 decimal places, this value is {0}", Decimal.Round(totalAmount));
            Console.WriteLine("Rounded to 4 decimal places, this value is {0}", Decimal.Round(totalAmount, 4));
            Console.WriteLine();

            totalAmount = -45.61M;
            Console.WriteLine("Profit last month was {0}", totalAmount);
            Console.WriteLine();

            decimal totalDollars1;
            decimal totalDollars2;

            totalDollars1 = Decimal.Floor(totalAmount);
            totalDollars2 = Decimal.Ceiling(totalAmount);

            Console.WriteLine("Rounding down this number is {0}", totalDollars1);
            Console.WriteLine("Roundign up this number is {0}", totalDollars2);
        }
Beispiel #6
0
        public static string Encode(byte[] input)
        {
            if (input.Length == 0)
            {
                return(string.Empty);
            }
            char[] chArray = new char[(int)Decimal.Ceiling((Decimal)input.Length / new Decimal(5)) * 8];
            int    num1    = 0;
            byte   num2    = 0;
            byte   num3    = 5;

            foreach (byte num4 in input)
            {
                byte num5 = (byte)((uint)num2 | (uint)num4 >> 8 - (int)num3);
                chArray[num1++] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"[(int)num5];
                if ((int)num3 < 3)
                {
                    byte num6 = (byte)((int)num4 >> 3 - (int)num3 & 31);
                    chArray[num1++] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"[(int)num6];
                    num3           += (byte)5;
                }
                num3 -= (byte)3;
                num2  = (byte)((int)num4 << (int)num3 & 31);
            }
            if (num1 != chArray.Length)
            {
                chArray[num1++] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"[(int)num2];
            }
            while (num1 < chArray.Length)
            {
                chArray[num1++] = '=';
            }
            return(new string(chArray).TrimEnd('='));
        }
Beispiel #7
0
        static decimal AmountAtTheEndInvestment(decimal numberCompaunded, decimal numberOfYears, decimal principalAmount, decimal rate)
        {
            decimal power            = numberCompaunded * numberOfYears;
            decimal amountInvestment = principalAmount * (decimal)Math.Pow((double)(1 + rate / numberCompaunded), (double)power);

            return(Decimal.Ceiling(amountInvestment * 100) / 100);
        }
Beispiel #8
0
        private void addPoint(HashSet <Point> result, Point p, float Thickness)
        {
            int half = Decimal.ToInt32(Decimal.Ceiling(new Decimal(Thickness / 2.0)));

            if (half % 2 == 1)
            {
                //drukuj normalnie
                for (int hor = p.X - (half - 1); hor <= p.X + (half - 1); hor++)
                {
                    for (int ver = p.Y - (half - 1); ver <= p.Y + (half - 1); ver++)
                    {
                        result.Add(new Point(hor, ver));
                    }
                }
            }
            else
            {
                //drukuj nienormalnie
                for (int hor = p.X - (half - 1); hor <= p.X + half; hor++)
                {
                    for (int ver = p.Y - (half - 1); ver <= p.Y + half; ver++)
                    {
                        result.Add(new Point(hor, ver));
                    }
                }
            }
        }
        private void CursorTimer_Tick(object sender, EventArgs e)
        {
            if (dt == null)
            {
                dt = DateTime.Now;
                return;
            }

            if (deltaX != 0 || deltaY != 0)
            {
                decimal speedX = maxSpeed * deltaX;
                decimal speedY = maxSpeed * deltaY;
                //Console.WriteLine("X: " + speedX + "\tY: " + speedY);

                double elapsed = (DateTime.Now - dt).TotalMilliseconds; //elapsed time (millis) since last loop

                double fraction = elapsed / 1000;

                int movementX = (int)Decimal.Ceiling(speedX * (decimal)fraction);
                int movementY = (int)Decimal.Ceiling(speedY * (decimal)fraction);

                string debug = string.Format("Cursor ({2}):\n\tX: {0}\n\tY: {1}", movementX, movementY, left.Scaling);
                cursor.Content = debug;

                //Console.WriteLine("X: " + movementX + "\tY: " + movementY);

                System.Drawing.Point p = System.Windows.Forms.Cursor.Position;

                System.Drawing.Point n = new System.Drawing.Point(p.X + movementX, p.Y - movementY);

                System.Windows.Forms.Cursor.Position = n;
            }
            dt = DateTime.Now;
        }
Beispiel #10
0
        private static decimal RoundHalfTowardsZeroForNegativeValue(decimal value)
        {
            var n = Decimal.Ceiling(value);

            // If 'value' is not a midpoint, we return the nearest integer.
            return(value - n == -0.5m ? n : HalfAwayFromZero(value, 0));
        }
Beispiel #11
0
        public static string ToNAMoneyFormat(this double n, Boolean tf)
        {
            double theMoney = n * 100;

            if (tf == true)
            {
                if (theMoney < 0)
                {
                    theMoney *= -1;
                    string str = string.Format("({0:C})", (Decimal.Ceiling((decimal)theMoney)) / 100); //Rounds the number accordingly
                    return(str);
                }
                else
                {
                    string str = string.Format("{0:C}", (Decimal.Ceiling((decimal)theMoney)) / 100); //Rounds the number accordingly
                    return(str);
                }
            }
            else
            {
                if (theMoney < 0)
                {
                    theMoney *= -1;
                    string str = string.Format("({0:C})", (Decimal.Floor((decimal)theMoney)) / 100); //Rounds the number downwards
                    return(str);
                }
                else
                {
                    string str = string.Format("{0:C}", (Decimal.Floor((decimal)theMoney)) / 100); //Rounds the number downwards
                    return(str);
                }
            }
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            Console.Write("What is the order amount?  ");
            decimal orderAmount = GetUserInput();

            Console.Write("What is the state?  ");
            string state = Console.ReadLine();

            state = state.ToUpper(); //Allow the user to enter a state in upper, lower, or mixed case.

            decimal tax    = 0m;
            string  output = string.Empty;

            if (state == "WI" || state == "WISCONSINE")
            {
                decimal stateTax = 0.055m;
                tax     = Decimal.Ceiling(orderAmount * stateTax * 100) / 100; //rounded up to the nearest cent
                output += String.Format("The subtotal is {0:c}.\nThe tax is {1:c}.\n", orderAmount, tax);
            }
            decimal total = Total(orderAmount, tax);

            output += String.Format("The total is {0:c}", total);

            Console.WriteLine(output);
        }
Beispiel #13
0
        private void BindResults(SearchResultDTO searchResult, string responseMessage)
        {
            if (searchResult != null && searchResult.Results.Count > 0)
            {
                rpItems.Visible      = true;
                divNoResults.Visible = false;

                rpItems.DataSource = searchResult.Results;
                rpItems.DataBind();

                int totalPages = 0;
                if (_itemsPerPage > 0)
                {
                    totalPages = Convert.ToInt32(Decimal.Ceiling(Convert.ToDecimal(searchResult.TotalItemCount) /
                                                                 Convert.ToDecimal(_itemsPerPage)));
                }

                //Set hidden field to help Paginator Item on Aspx page.
                hfTotalPages.Value = totalPages.ToString();
            }
            else
            {
                rpItems.Visible      = false;
                divNoResults.Visible = true;
                divNoResults.Visible = true;
                HtmlGenericControl messageToShow = new HtmlGenericControl();
                messageToShow.TagName   = "h2";
                messageToShow.InnerHtml = responseMessage;
                divNoResults.Controls.Add(messageToShow);
            }
        }
        public ActionResult <IEnumerable <Produto> > Get(
            [FromQuery] int p            = 1,
            [FromQuery] int c            = 50,
            [FromQuery] string q         = null,
            [FromQuery] long?idMarca     = null,
            [FromQuery] long?idCategoria = null,
            [FromQuery] string o         = "Nome",
            [FromQuery] bool oDescending = false)
        {
            try
            {
                var res = _service.Get(p, c, q, idMarca, idCategoria, o, oDescending, out long total);

                return(Ok(new
                {
                    Produtos = res,
                    RegisterCount = total,
                    PageCount = Decimal.Ceiling(total / c)
                }));
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Get ({p}, {c}, {q}, {idMarca}, {idCategoria}, {o}, {oDescending}) {typeof(Produto)}");
                return(StatusCode(500));
            }
        }
Beispiel #15
0
        public static int CalculateEndFrameFromAnimationGroupNodes(AnimationGroup animationGroup)
        {
            int endFrame = 0;

            foreach (Guid nodeGuid in animationGroup.NodeGuids)
            {
                IINode node = Tools.GetINodeByGuid(nodeGuid);
                if (node.IsAnimated && node.TMController != null)
                {
                    int lastKey = 0;
                    if (node.TMController.PositionController != null)
                    {
                        int posKeys = node.TMController.PositionController.NumKeys;
                        lastKey = Math.Max(lastKey, node.TMController.PositionController.GetKeyTime(posKeys - 1));
                    }

                    if (node.TMController.RotationController != null)
                    {
                        int rotKeys = node.TMController.RotationController.NumKeys;
                        lastKey = Math.Max(lastKey, node.TMController.RotationController.GetKeyTime(rotKeys - 1));
                    }

                    if (node.TMController.ScaleController != null)
                    {
                        int scaleKeys = node.TMController.ScaleController.NumKeys;
                        lastKey = Math.Max(lastKey, node.TMController.ScaleController.GetKeyTime(scaleKeys - 1));
                    }
                    decimal keyTime = Decimal.Ceiling(lastKey / 160);
                    endFrame = Math.Max(endFrame, Decimal.ToInt32(keyTime));
                }
            }

            return((endFrame != 0)? endFrame : animationGroup.FrameEnd);
        }
Beispiel #16
0
        private decimal checkPriceOnSale(IEnumerable <MyPrice> searchTicket)
        {
            decimal total = 0;

            if (checkBox1.Checked == true)
            {
                if (checkBox2.Checked == true)
                {
                    foreach (var item in searchTicket)
                    {
                        var final = item.ticketprice;
                        final = Decimal.Ceiling(Decimal.Multiply(Decimal.Multiply(final, 2), Convert.ToDecimal(0.81)));
                        foreach (var i in searchTicket)
                        {
                            label5.Text = "此為來回優惠票" + '\n' + "上車地點-下車地點:   " + '\n' + i.startstation + "-" + i.endstation + '\n' + i.endstation + "-" + i.startstation;
                        }
                        return(final);
                    }
                }
                else
                {
                    foreach (var item in searchTicket)
                    {
                        var final = item.ticketprice;
                        final = Decimal.Ceiling(Decimal.Multiply(Decimal.Multiply(final, 2), Convert.ToDecimal(0.9)));
                        foreach (var i in searchTicket)
                        {
                            label5.Text = "此為來回票" + '\n' + "上車地點-下車地點:   " + '\n' + i.startstation + "-" + i.endstation + '\n' + i.endstation + "-" + i.startstation;
                        }
                        return(final);
                    }
                }
            }
            else if (checkBox2.Checked == true)
            {
                foreach (var item in searchTicket)
                {
                    var final = item.ticketprice;
                    final = Decimal.Ceiling(Decimal.Multiply(final, Convert.ToDecimal(0.9)));
                    foreach (var i in searchTicket)
                    {
                        label5.Text = "優惠票" + '\n' + "上車地點-下車地點:" + '\n' + i.startstation + "-" + i.endstation;
                    }
                    return(final);
                }
            }
            else
            {
                foreach (var item in searchTicket)
                {
                    foreach (var i in searchTicket)
                    {
                        label5.Text = "上車地點-下車地點:" + '\n' + i.startstation + "-" + i.endstation;
                    }
                    return(item.ticketprice);
                }
            }
            return(total);
        }
Beispiel #17
0
        /**
         * RoundUp when the value >=5 , Otherwise RoundDown
         */
        public static decimal ToHalfAdjust(this decimal dValue, int iDigits)
        {
            decimal dCoef        = (decimal)System.Math.Pow(10D, iDigits);
            decimal decRemaining = 0.5M;

            return(dValue > 0 ? Decimal.Floor(((dValue * dCoef) + decRemaining)) / dCoef :
                   Decimal.Ceiling(((dValue * dCoef) - decRemaining)) / dCoef);
        }
Beispiel #18
0
        //
        //切り上げさせる
        //
        public static string updKiriage(string strData)
        {
            Decimal d = Convert.ToDecimal(strData);

            strData = Convert.ToString(Decimal.Ceiling(d));

            return(strData);
        }
Beispiel #19
0
 public static void TestCeiling()
 {
     // Decimal Decimal.Ceiling(Decimal)
     Assert.Equal <Decimal>(123, Decimal.Ceiling((Decimal)123));
     Assert.Equal <Decimal>(124, Decimal.Ceiling((Decimal)123.123));
     Assert.Equal <Decimal>(-123, Decimal.Ceiling((Decimal)(-123.123)));
     Assert.Equal <Decimal>(124, Decimal.Ceiling((Decimal)123.567));
     Assert.Equal <Decimal>(-123, Decimal.Ceiling((Decimal)(-123.567)));
 }
Beispiel #20
0
        public static Money Ceiling(Money a)
        {
            if (IsNaN(a))
            {
                return(NaN);
            }

            return(Decimal.Ceiling(a._value.Value));
        }
 public void TestCeiling()
 {
     // Decimal Decimal.Ceiling(Decimal)
     Assert.AreEqual(123, Decimal.Ceiling((Decimal)123));
     Assert.AreEqual(124, Decimal.Ceiling((Decimal)123.123));
     Assert.AreEqual(-123, Decimal.Ceiling((Decimal)(-123.123)));
     Assert.AreEqual(124, Decimal.Ceiling((Decimal)123.567));
     Assert.AreEqual(-123, Decimal.Ceiling((Decimal)(-123.567)));
 }
Beispiel #22
0
        public ActionResult Navigate(int start, int index, string command)
        {
            string         text         = Session["text"].ToString();
            SearchResponse returnResult = new SearchResponse();
            SearchResponse result       = null;

            if (Convert.ToBoolean(Session["category"]))
            {
                result = Session["searchResponseCategory"] as SearchResponse;
            }
            else
            {
                result = WebCache.Get("searchResponse" + text);
            }
            returnResult.StartPosition   = start;
            returnResult.CurrentPosition = index;
            returnResult.TotalRecords    = result.TotalRecords;
            returnResult.keywords        = result.keywords;
            decimal pages = Decimal.Ceiling(Convert.ToDecimal(returnResult.TotalRecords) / 10);

            int from = (index * 10) - 10;
            int to   = (index * 10);

            if (to > result.TotalRecords)
            {
                to = result.TotalRecords;
            }
            if (from > to)
            {
                from = (Convert.ToInt32(pages) - 1) * 10;
                returnResult.CurrentPosition = Convert.ToInt32(pages);
            }
            Content[] returnContents = new Content[to - from];
            int       current        = 0;

            for (int i = from; i < to; i++)
            {
                returnContents[current] = result.Contents[i];
                current++;
            }
            returnResult.Contents = returnContents;


            if (command == "next")
            {
                if (returnResult.TotalRecords > 0)
                {
                    if (pages >= start + 10)
                    {
                        returnResult.StartPosition += 10;
                    }
                }
            }

            return(PartialView("Search", returnResult));
        }
Beispiel #23
0
        // 事件
        private void OnDataRefreshing(DataRefreshEventArgs e)
        {
            if ((DataRefreshing != null))
            {
                DataRefreshing(this, e);
                if (e.DataSource != null && e.RowCount > 0)
                {
                    CurrentPage = e.CurrentPage;
                    RowsPerPage = e.RowsPerPage;
                    RowCount    = e.RowCount;
                    decimal rowCountDecimal = RowCount;
                    PageCount = Convert.ToInt32(Decimal.Ceiling(rowCountDecimal / RowsPerPage));

                    #region
                    ///当CurrentPage > PageCount 时 ,页面会出错
                    CurrentPage = CurrentPage > PageCount ? PageCount : CurrentPage;
                    #endregion  end
                    _controlledGridView.DataSource = e.DataSource;
                    _controlledGridView.DataBind();


                    // 设置导航按钮的可用状态
                    btnPrevious.Enabled = (_currentPage != 1);
                    btnFirst.Enabled    = btnPrevious.Enabled;

                    btnNext.Enabled = (_currentPage != _pageCount);
                    btnLast.Enabled = btnNext.Enabled;
                }
                else if (e.DataSource != null && e.RowCount == 0)
                {
                    CurrentPage = 1;
                    RowsPerPage = e.RowsPerPage;
                    RowCount    = e.RowCount;
                    decimal rowCountDecimal = RowCount;
                    PageCount = Convert.ToInt32(Decimal.Ceiling(rowCountDecimal / RowsPerPage));
                    _controlledGridView.DataSource = e.DataSource;
                    _controlledGridView.DataBind();

                    // 设置导航按钮的可用状态
                    btnPrevious.Enabled = false;
                    btnFirst.Enabled    = btnPrevious.Enabled;

                    btnNext.Enabled = false;
                    btnLast.Enabled = btnNext.Enabled;
                }
                else
                {
                    _controlledGridView.DataSource = e.DataSource;
                    _controlledGridView.DataBind();
                }
                if (_isShowHead)
                {
                    _controlledGridView.Rows[0].Visible = false;
                }
            }
        }
Beispiel #24
0
        /// <summary>
        /// データがロードされた後に発生します.
        /// </summary>
        //public event EventHandler<EventArgs> Loaded = delegate { };

        /// <summary>
        /// 範囲を制限したデータを返します。
        /// </summary>
        /// <param name="start"></param>
        /// <param name="stop"></param>
        /// <returns></returns>
        public WideScan GetRestrictedData(decimal start, decimal stop)
        {
            var b = Convert.ToInt32(Decimal.Floor((start - Parameter.Start) / Parameter.Step));
            var e = Convert.ToInt32(Decimal.Ceiling((stop - Parameter.Start) / Parameter.Step));

            return(new WideScan
            {
                _data = this.Data.GetSubData(b, e),
                _scanParameter = this.Parameter.ShrinkRange(b, e)
            });
        }
Beispiel #25
0
 public static void Main()
 {
     decimal[] values = { 12.6m, 12.1m, 9.5m, 8.16m, .1m, -.1m, -1.1m,
                          -1.9m, -3.9m };
     Console.WriteLine("{0,-8} {1,10} {2,10}\n",
                       "Value", "Ceiling", "Floor");
     foreach (decimal value in values)
     {
         Console.WriteLine("{0,-8} {1,10} {2,10}", value,
                           Decimal.Ceiling(value), Decimal.Floor(value));
     }
 }
Beispiel #26
0
        // Calculates user quote.
        private decimal CalcQuote(Quote quote)
        {
            decimal total = 50m; // base of $50

            TimeSpan timespan = DateTime.Now - quote.DateOfBirth;
            int      years    = Convert.ToInt32(timespan.Days) / 365;

            if (years < 25)
            {
                if (years < 18)
                {
                    total += 100;             // Add 100 if under 18 years old.
                }
                else
                {
                    total += 25;  // Add 25 if under 25 but over 18 years old.
                }
            }
            if (years > 100)
            {
                total += 25;              // Add $25 if over 100 years old.
            }
            if (quote.CarYear < 2000 || quote.CarYear > 2015)
            {
                total += 25;                                               // Add $25 if car older than 2000 or newer than 2015.
            }
            if (quote.CarMake.ToLower() == "porsche")
            {
                total += 25; // Add $25 if car is a Porsche.
                if (quote.CarModel.ToLower() == "911 carrera")
                {
                    total += 25;                                            // Add another $25 if Porsche is a 911 Carrera.
                }
            }
            for (int i = 0; i < quote.TicketNumber; i++)
            {
                total += 10; //Add $10 for every speeding ticket.
            }
            if (quote.DUI)
            {
                total = total * 1.25m;            // Add 25% if they have a DUI.
            }
            if (quote.FullCoverage)
            {
                total = total * 1.5m;             // Add 50% for Full Coverage.
            }
            total = Decimal.Ceiling(total * 100); //Ensure total is rounded up.
            total = total / 100;                  // Ensure total only shows two decimal places.

            return(total);
        }
Beispiel #27
0
        public AddCartLineResult Execute(
            IUnitOfWork unitOfWork,
            AddCartLineParameter parameter,
            AddCartLineResult result)
        {
            if (!parameter.QtyOrdered.HasValue)
            {
                return(result);
            }
            OrderLine cartLine    = result.CartLine;
            Decimal   qtyOrdered1 = !this.cartSettings.ReplaceOnAdd || !(parameter.Cart.Status != "Requisition") ? parameter.QtyOrdered.Value + cartLine.QtyOrdered : parameter.QtyOrdered.Value;

            if (cartLine.Product.MinimumOrderQty > 0)
            {
                ProductUnitOfMeasure productUnitOfMeasure = cartLine.Product.ProductUnitOfMeasures.FirstOrDefault <ProductUnitOfMeasure>((Func <ProductUnitOfMeasure, bool>)(o =>
                {
                    if (o.UnitOfMeasure == cartLine.UnitOfMeasure)
                    {
                        return(o.QtyPerBaseUnitOfMeasure > Decimal.Zero);
                    }
                    return(false);
                }));
                Decimal num = productUnitOfMeasure != null ? productUnitOfMeasure.QtyPerBaseUnitOfMeasure : Decimal.One;
                if (qtyOrdered1 * num < (Decimal)cartLine.Product.MinimumOrderQty)
                {
                    qtyOrdered1          = Decimal.Ceiling((Decimal)cartLine.Product.MinimumOrderQty / num);
                    result.IsQtyAdjusted = true;
                }
            }
            Decimal qtyOrdered2 = this.roundingRulesProvider.ApplyRoundingRules(cartLine.Product, cartLine.UnitOfMeasure, qtyOrdered1);

            if (qtyOrdered2 != qtyOrdered1)
            {
                result.IsQtyAdjusted = true;
            }
            this.orderLineUtilities.SetQtyOrdered(cartLine, qtyOrdered2);

            // BUSA-1319: Limit Qty Per Product on PLP, PDP, QuickOrder, ReOrder, Saved Order
            var maxProductQty = cartLine.Product?.CustomProperties.Where(x => x.Name.EqualsIgnoreCase("maxProductQty")).Select(v => v.Value).FirstOrDefault() ?? "0";

            if (!string.IsNullOrEmpty(maxProductQty) && Convert.ToInt32(maxProductQty) != 0 && cartLine.QtyOrdered > Convert.ToDecimal(maxProductQty))
            {
                cartLine.QtyOrdered  = Convert.ToDecimal(maxProductQty);
                result.IsQtyAdjusted = true;
            }
            // BUSA- 1319: END

            return(result);
        }
Beispiel #28
0
        public static object ToInt(decimal self)
        {
            decimal rounded;

            if (self >= 0)
            {
                rounded = Decimal.Floor(self);
            }
            else
            {
                rounded = Decimal.Ceiling(self);
            }

            return(Protocols.Normalize(rounded));
        }
Beispiel #29
0
        public int GetSavedPiecesCount()
        {
            if (!File.Exists(PathSource))
            {
                return(0);
            }
            lock (lockObject)
            {
                //BinaryReader br = new BinaryReader(new FileStream(PathSource, FileMode.Open, FileAccess.Read));
                long    numBytes = new FileInfo(PathSource).Length;
                decimal r1       = Decimal.Ceiling((decimal)numBytes / (decimal)PiecesLength); // czesci pobierane sa po polei wg indeksu, wiec rozmiar pliku na dysku / rozmiar czesci = ilosc posiadanych czesci

                return((int)r1);
            }
        }
        //---Pagination---//
        public IActionResult Index(int?page)
        {
            TempData["controllerName"] = this.ControllerContext.RouteData.Values["controller"].ToString();

            ViewBag.PageCount = Decimal.Ceiling((decimal)_context.LatestFromBlogs.Where(b => b.IsDeleted == false).Count() / 3);
            ViewBag.page      = page;
            if (page == null)
            {
                List <LatestFromBlog> latestFromBlog = _context.LatestFromBlogs.Where(b => b.IsDeleted == false).Take(3).ToList();
                return(View(latestFromBlog));
            }
            List <LatestFromBlog> LatestFromBlog = _context.LatestFromBlogs.Where(b => b.IsDeleted == false).Skip(((int)page - 1) * 3).Take(3).ToList();

            return(View(LatestFromBlog));
        }