Ejemplo n.º 1
0
 public CalcViewModel()
 {
     Model         = new CalcModel();
     tempNumber    = 0;
     lastOperation = LastOperation.None;
     bNewEntry     = false;
 }
Ejemplo n.º 2
0
        public void PerformCalculations()
        {
            //Reset
            Reset = true;
            //Add
            double value = Double.Parse(ResultLabel.Content.ToString());

            if (LastOperation.CompareTo(Flag.Add) == 0)
            {
                //Perform math on the total based off the value coming in. Using the Cache.
                Total += value;
                Console.WriteLine(Total);
                //return the Operation to Default
                Operation = Flag.Default;
                //Show the total on display
                ResultLabel.Content = Total.ToString();
            }
            //Subtract
            else if (LastOperation.CompareTo(Flag.Subtract) == 0)
            {
                //Perform math on the total based off the value coming in. Using the Cache.
                Total -= value;
                //return the Operation to Default
                Operation = Flag.Default;
                //Show the total on display
                ResultLabel.Content = Total.ToString();
            }
            //Divide
            else if (LastOperation.CompareTo(Flag.Divide) == 0)
            {
                //Perform math on the total based off the value coming in. Using the Cache.
                Total /= value;
                //return the Operation to Default
                Operation = Flag.Default;
                //Show the total on display
                ResultLabel.Content = Total.ToString();
            }

            //Multiply
            else if (LastOperation.CompareTo(Flag.Multiply) == 0)
            {
                //Perform math on the total based off the value coming in. Using the Cache.
                Total *= value;
                //return the Operation to Default
                Operation = Flag.Default;
                //Show the total on display
                ResultLabel.Content = Total.ToString();
            }
            //Modulo
            else if (LastOperation.CompareTo(Flag.Modulo) == 0)
            {
                //Perform math on the total based off the value coming in. Using the Cache.
                Total %= value;
                //return the Operation to Default
                Operation = Flag.Default;
                //Show the total on display
                ResultLabel.Content = Total.ToString();
            }
        }
Ejemplo n.º 3
0
 public AirthmeticViewModel()
 {
     Model         = new AirthmeticModel();
     tempNumber    = 0;
     lastOperation = LastOperation.None;
     bNewEntry     = false;
     InitializeCommand();
 }
Ejemplo n.º 4
0
 public void clearAll()
 {
     Model.Number  = 0;
     updateNumber  = 0;
     tempNumber    = 0;
     bNewEntry     = false;
     lastOperation = LastOperation.None;
 }
Ejemplo n.º 5
0
 public void OnDivideCommand()
 {
     if (lastOperation == LastOperation.Divide)
     {
         double sum = tempNumber / updateNumber;
         clear();
         updateNumber = sum;
     }
     tempNumber    = updateNumber;
     bNewEntry     = true;
     lastOperation = LastOperation.Divide;
 }
Ejemplo n.º 6
0
 public void OnMultiplyCommand()
 {
     if (lastOperation == LastOperation.Multiply)
     {
         double sum = tempNumber * updateNumber;
         clear();
         updateNumber = sum;
     }
     tempNumber    = updateNumber;
     bNewEntry     = true;
     lastOperation = LastOperation.Multiply;
 }
Ejemplo n.º 7
0
 public void OnSubtractCommand()
 {
     if (lastOperation == LastOperation.Subtract)
     {
         double sum = tempNumber - updateNumber;
         clear();
         updateNumber = sum;
     }
     tempNumber    = updateNumber;
     bNewEntry     = true;
     lastOperation = LastOperation.Subtract;
 }
Ejemplo n.º 8
0
 public void Divide()
 {
     if (lastOperation == LastOperation.Divide)
     {
         double sum = Model.Divide(tempNumber, updateNumber);
         clear();
         updateNumber = sum;
     }
     tempNumber    = updateNumber;
     bNewEntry     = true;
     lastOperation = LastOperation.Divide;
 }
Ejemplo n.º 9
0
 public void Multiply()
 {
     if (lastOperation == LastOperation.Multiply)
     {
         double sum = Model.Multiply(tempNumber, updateNumber);
         clear();
         updateNumber = sum;
     }
     tempNumber    = updateNumber;
     bNewEntry     = true;
     lastOperation = LastOperation.Multiply;
 }
Ejemplo n.º 10
0
 public void subtract()
 {
     if (lastOperation == LastOperation.Subtract)
     {
         double sum = Model.subtract(tempNumber, updateNumber);
         clear();
         updateNumber = sum;
     }
     tempNumber    = updateNumber;
     bNewEntry     = true;
     lastOperation = LastOperation.Subtract;
 }
Ejemplo n.º 11
0
        public void OnAddCommand()
        {
            if (lastOperation == LastOperation.Add)
            {
                double sum = updateNumber + tempNumber;
                clear();
                updateNumber = sum;
            }
            tempNumber = updateNumber;
            bNewEntry  = true;

            lastOperation = LastOperation.Add;
        }
Ejemplo n.º 12
0
        public void add()
        {
            if (lastOperation == LastOperation.Add)
            {
                double sum = Model.add(updateNumber, tempNumber);
                clear();
                updateNumber = sum;
            }
            tempNumber = updateNumber;
            bNewEntry  = true;

            lastOperation = LastOperation.Add;
        }
Ejemplo n.º 13
0
        public string Statement()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"====== Account no. {AccountNumber} ({BankName}) ======");
            sb.AppendLine($"Balance: {Balance}\t\tLast Operation: {LastOperation.ToString("yyyy-MM-dd")}");
            sb.AppendLine("=======================================================");
            sb.AppendLine("== MOVEMENTS ==========================================");
            foreach (IMovement movement in _movements.OrderBy(m => m.IssueDate))
            {
                sb.AppendLine(movement.ToString());
            }
            sb.AppendLine("=======================================================");

            return(sb.ToString());
        }
Ejemplo n.º 14
0
 public void equal()
 {
     if (lastOperation == LastOperation.Add)
     {
         OnAddCommand();
     }
     else if (lastOperation == LastOperation.Multiply)
     {
         OnMultiplyCommand();
     }
     else if (lastOperation == LastOperation.Divide)
     {
         OnDivideCommand();
     }
     else if (lastOperation == LastOperation.Subtract)
     {
         OnSubtractCommand();
     }
     lastOperation = LastOperation.None;
 }
Ejemplo n.º 15
0
 public void equal()
 {
     if (lastOperation == LastOperation.Add)
     {
         add();
     }
     else if (lastOperation == LastOperation.Multiply)
     {
         Multiply();
     }
     else if (lastOperation == LastOperation.Divide)
     {
         Divide();
     }
     else if (lastOperation == LastOperation.Subtract)
     {
         subtract();
     }
     lastOperation = LastOperation.None;
 }
Ejemplo n.º 16
0
        // Arrange the Adorners.
        protected override Size ArrangeOverride(Size finalSize)
        {
            // desiredWidth and desiredHeight are the width and height of the element that's being adorned.
            // These will be used to place the ResizingAdorner at the corners of the adorned element.
            var bbb = CurrentEditor.GetMoleculeBoundingBox(AdornedMolecules);

            if (LastOperation != null)
            {
                bbb = LastOperation.TransformBounds(bbb);
            }

            TopLeftHandle.Arrange(new Rect(bbb.Left - _halfThumbWidth, bbb.Top - _halfThumbWidth, _thumbWidth.Value,
                                           _thumbWidth.Value));
            TopRightHandle.Arrange(new Rect(bbb.Left + bbb.Width - _halfThumbWidth, bbb.Top - _halfThumbWidth,
                                            _thumbWidth.Value,
                                            _thumbWidth.Value));
            BottomLeftHandle.Arrange(new Rect(bbb.Left - _halfThumbWidth, bbb.Top + bbb.Height - _halfThumbWidth,
                                              _thumbWidth.Value, _thumbWidth.Value));
            BottomRightHandle.Arrange(new Rect(bbb.Left + bbb.Width - _halfThumbWidth,
                                               bbb.Height + bbb.Top - _halfThumbWidth, _thumbWidth.Value,
                                               _thumbWidth.Value));

            //add the rotator
            _xPlacement     = (bbb.Left + bbb.Right) / 2;
            _yPlacement     = bbb.Top - RotateHandle.Height * 3;
            _rotateThumbPos = new Point(_xPlacement, _yPlacement);

            if (BigThumb.IsDragging ||
                TopLeftHandle.IsDragging ||
                TopRightHandle.IsDragging ||
                BottomLeftHandle.IsDragging ||
                BottomRightHandle.IsDragging)
            {
                RotateHandle.Visibility = Visibility.Hidden;
            }
            else
            {
                RotateHandle.Visibility = Visibility.Visible;
                SetCentroid();
            }

            if (Rotating && LastOperation != null)
            {
                _rotateThumbPos = LastOperation.Transform(_rotateThumbPos);
            }

            Vector rotateThumbTweak = new Vector(-RotateHandle.Width / 2, -RotateHandle.Height / 2);
            Point  newLoc           = _rotateThumbPos + rotateThumbTweak;

            if (Rotating && LastOperation != null)
            {
                TopLeftHandle.Visibility     = Visibility.Collapsed;
                TopRightHandle.Visibility    = Visibility.Collapsed;
                BottomLeftHandle.Visibility  = Visibility.Collapsed;
                BottomRightHandle.Visibility = Visibility.Collapsed;
                BigThumb.Visibility          = Visibility.Collapsed;
            }
            else
            {
                TopLeftHandle.Visibility     = Visibility.Visible;
                TopRightHandle.Visibility    = Visibility.Visible;
                BottomLeftHandle.Visibility  = Visibility.Visible;
                BottomRightHandle.Visibility = Visibility.Visible;
                BigThumb.Visibility          = Visibility.Visible;
            }

            RotateHandle.Arrange(new Rect(newLoc.X, newLoc.Y, RotateHandle.Width, RotateHandle.Height));

            base.ArrangeOverride(finalSize);
            return(finalSize);
        }