Esempio n. 1
0
 public MainViewModel()
 {
     Value  = "0";
     Number = new ParametrizedRelayCommand(
         param =>
     {
         string newChar = param.ToString();
         if (Value == "0" && newChar == "0")
         {
             Value = "0";
         }
         if (Value == "0")
         {
             Value = newChar;
         }
         else if (Value.EndsWith(".0") && newChar != "0")
         {
             Value = Value.Remove(Value.Length - 1, 1) + newChar;
         }
         else
         {
             Value += newChar;
         }
     },
         param => true
         );
     Point = new RelayCommand(
         () =>
     {
         Value += ".0";
         Point.RaiseCanExecuteChanged();
     },
         () => (!Value.Contains("."))
         );
     Sign = new RelayCommand(
         () => {
         if (Value.StartsWith("-"))
         {
             Value = Value.Substring(1, Value.Length - 1);
         }
         else
         {
             Value = "-" + Value;
         }
     },
         () => true
         );
 }
 public MainViewModel()
 {
     NumberButton = new ParametrizedRelayCommand(
         (param) =>
     {
         TextMessage += param;
     },
         () => { return(true); }
         );
     Sign = new RelayCommand(
         () =>
     {
         if (TextMessage.Length > 0)
         {
             TextMessage = Convert.ToString((Convert.ToDouble(TextMessage) * (-1)));
         }
     },
         () => { return(true); }
         );
     Point = new RelayCommand(
         () =>
     {
         if ((!TextMessage.Contains(".")) && TextMessage.Length > 0)
         {
             TextMessage += ".";
         }
     },
         () => { return(true); }
         );
     Reset = new RelayCommand(
         () =>
     {
         TextMessage  = "";
         _storedValue = "";
     },
         () => { return(true); }
         );
     Result = new RelayCommand(
         () =>
     {
         if (_operation == 1)
         {
             TextMessage = Convert.ToString(Convert.ToDouble(_storedValue) + Convert.ToDouble(TextMessage));
             _operation  = 0;
         }
         if (_operation == 2)
         {
             TextMessage = Convert.ToString(Convert.ToDouble(_storedValue) - Convert.ToDouble(TextMessage));
             _operation  = 0;
         }
         if (_operation == 3)
         {
             TextMessage = Convert.ToString(Convert.ToDouble(_storedValue) * Convert.ToDouble(TextMessage));
             _operation  = 0;
         }
         if (_operation == 4)
         {
             if (TextMessage == "0")
             {
                 TextMessage = "Nonono Zero is not allowed!!!";
             }
             else
             {
                 TextMessage = Convert.ToString(Convert.ToDouble(_storedValue) / Convert.ToDouble(TextMessage));
                 _operation  = 0;
             }
         }
         if (_function == 1)
         {
             TextMessage = Convert.ToString(Math.Pow(Convert.ToDouble(_storedValue), Convert.ToDouble(TextMessage)));
             _function   = 0;
         }
         if (_function == 2)
         {
             TextMessage = Convert.ToString(Math.Sqrt(Convert.ToDouble(_storedValue)));
             _function   = 0;
         }
         if (_function == 3)
         {
             TextMessage = Convert.ToString(Math.Log(Convert.ToDouble(TextMessage), Convert.ToDouble(_storedValue)));
             _function   = 0;
         }
         if (_function == 4)
         {
             TextMessage = Convert.ToString(Math.Sin(Convert.ToDouble(_storedValue)));
             _function   = 0;
         }
     },
         () => { return(true); }
         );
     OperationButton = new ParametrizedRelayCommand(
         (param) =>
     {
         _storedValue = TextMessage;
         TextMessage  = "";
         if (Convert.ToString(param) == "+")
         {
             _operation = 1;
         }
         if (Convert.ToString(param) == "-")
         {
             _operation = 2;
         }
         if (Convert.ToString(param) == "*")
         {
             _operation = 3;
         }
         else if (Convert.ToString(param) == "/")
         {
             _operation = 4;
         }
     },
         () => { return(true); }
         );
     FunctionButton = new ParametrizedRelayCommand(
         (param) =>
     {
         _storedValue = TextMessage;
         TextMessage  = "";
         if (Convert.ToString(param) == "X**Y")
         {
             _function = 1;
         }
         if (Convert.ToString(param) == "Sqrt")
         {
             _function = 2;
         }
         if (Convert.ToString(param) == "Log")
         {
             _function = 3;
         }
         if (Convert.ToString(param) == "Sin")
         {
             _function = 4;
         }
     },
         () => { return(true); }
         );
 }
Esempio n. 3
0
        public VjuMoudl()
        {
            Point = new RelayCommand(
                () =>
            {
                if (!(Text.Contains(".")) && Text.Length > 0)
                {
                    Text += ".";
                }
            }
                );

            Sign = new RelayCommand(
                () =>
            {
                Text = Convert.ToString((Convert.ToDouble(Text) + (-1)));
            }
                );

            Reset = new RelayCommand(
                () =>
            {
                Text         = "";
                _storedValue = "";
            }
                );

            Number = new ParametrizedRelayCommand(
                (param) =>
            {
                Text += param;
            }
                );



            //operace (rychlá akce)
            Operation = new ParametrizedRelayCommand(
                (param) =>
            {
                _storedValue = Text;
                Text         = "";
                if (Convert.ToString(param) == "+")
                {
                    _oper = 1;
                }
                if (Convert.ToString(param) == "-")
                {
                    _oper = 2;
                }
                if (Convert.ToString(param) == "*")
                {
                    _oper = 3;
                }
                if (Convert.ToString(param) == "/")
                {
                    _oper = 4;
                }
            }
                );

            Function = new ParametrizedRelayCommand(
                (param) =>
            {
                _storedValue = Text;
                if (Convert.ToString(param) == "sin")
                {
                    _func = 1;
                }
                if (Convert.ToString(param) == "cos")
                {
                    _func = 2;
                }
                if (Convert.ToString(param) == "log")
                {
                    _func = 3;
                }
                if (Convert.ToString(param) == "moc")
                {
                    _func = 4;
                }
            }
                );

            Result = new RelayCommand(
                () =>
            {
                if (_oper == 1)
                {
                    Text = Convert.ToString(Convert.ToDouble(_storedValue) + Convert.ToDouble(Text));
                }
                if (_oper == 2)
                {
                    Text = Convert.ToString(Convert.ToDouble(_storedValue) - Convert.ToDouble(Text));
                }
                if (_oper == 3)
                {
                    Text = Convert.ToString(Convert.ToDouble(_storedValue) * Convert.ToDouble(Text));
                }
                if (_oper == 4)
                {
                    if (Text == "0")
                    {
                        Text = "Nulou ne, takhle to nefunguje";
                    }
                    else
                    {
                        Text = Convert.ToString(Convert.ToDouble(_storedValue) / Convert.ToDouble(Text));
                    }
                }



                if (_func == 1)
                {
                    Text = Convert.ToString(Math.Sin(Convert.ToDouble(Text)));
                }
                if (_func == 2)
                {
                    Text = Convert.ToString(Math.Cos(Convert.ToDouble(Text)));
                }
                if (_func == 3)
                {
                    Text = Convert.ToString(Math.Log(Convert.ToDouble(Text)));
                }
                if (_func == 4)
                {
                    Text = Convert.ToString(Convert.ToDouble(Text) * Convert.ToDouble(Text));
                }
            }
                );
        }
Esempio n. 4
0
        public MainViewModel()
        {
            Value  = "0";
            Number = new ParametrizedRelayCommand(
                param =>
            {
                string newChar = param.ToString();
                if (Value == "0" && newChar == "0")
                {
                    Value = "0";
                }
                else if (Value == "0")
                {
                    Value = newChar;
                }
                else if (Value.EndsWith(".0") && newChar != "0")
                {
                    Value = Value.Remove(Value.Length - 1, 1) + newChar;
                }
                else if (Value.EndsWith(".0") && newChar == "0")
                {
                    Value = "0" + newChar;
                }
                else
                {
                    Value += newChar;
                }
            },
                param => true
                );
            Point = new RelayCommand(
                () =>
            {
                Value += ".0";
                Point.RaiseCanExecuteChanged();
            },
                () => (!Value.Contains("."))
                );
            Sign = new RelayCommand(
                () =>
            {
                if (Value.StartsWith("-"))
                {
                    Value = Value.Substring(1, Value.Length - 1);
                }
                else
                {
                    Value = "-" + Value;
                }
            },
                () => true
                );
            Reset = new RelayCommand(
                () =>
            {
                Value = "0";
                Point.RaiseCanExecuteChanged();
            },
                () => true
                );
            Operation = new ParametrizedRelayCommand(
                param =>
            {
                Point.RaiseCanExecuteChanged();
                switch (param)
                {
                case "+":
                    Value1 = Value;
                    Value  = "0";
                    Oper   = "+";
                    break;

                case "-":
                    Value1 = Value;
                    Value  = "0";
                    Oper   = "-";
                    break;

                case "*":
                    Value1 = Value;
                    Value  = "0";
                    Oper   = "*";
                    break;

                case "/":
                    Value1 = Value;
                    Value  = "0";
                    Oper   = "/";
                    break;

                case "^":
                    Value1 = Value;
                    Value  = "0";
                    Oper   = "^";
                    break;

                case "√x":
                    Value1 = Value;
                    Oper   = "√x";
                    break;

                case "sin(x)":
                    Value1 = Value;
                    Oper   = "sin(x)";
                    break;

                case "cos(x)":
                    Value1 = Value;
                    Oper   = "cos(x)";
                    break;

                case "=":
                    Value2   = Value;
                    double x = Double.Parse(Value1);
                    double y = Double.Parse(Value2);
                    double result;
                    switch (Oper)
                    {
                    case "+":
                        result = x + y;
                        Value  = result.ToString();
                        break;

                    case "-":
                        result = x - y;
                        Value  = result.ToString();
                        break;

                    case "*":
                        result = x * y;
                        Value  = result.ToString();
                        break;

                    case "/":
                        if (y == 0)
                        {
                            Value = "Dělení nulou";
                        }
                        else
                        {
                            result = x / y;
                            Value  = result.ToString();
                        }
                        break;

                    case "^":
                        result = Math.Pow(x, y);
                        Value  = result.ToString();
                        break;

                    case "√x":
                        if (x < 0)
                        {
                            Value = "Odmocnění záp**ného čísla";
                        }
                        else
                        {
                            result = Math.Sqrt(x);
                            Value  = result.ToString();
                        }
                        break;

                    case "sin(x)":
                        result = Math.Sin(x);
                        Value  = result.ToString();
                        break;

                    case "cos(x)":
                        result = Math.Cos(x);
                        Value  = result.ToString();
                        break;

                    default:
                        break;
                    }
                    break;

                default:
                    break;
                }
            },
                param => true
                );
        }