Exemple #1
0
        private void Apply()
        {
            try
            {
                var value = 0;

                if (_currentValue.Contains("+"))
                {
                    var splitted = _currentValue.Split('+');

                    foreach (var item in splitted)
                    {
                        if (item.Any(char.IsDigit))
                        {
                            value += System.Convert.ToInt32(item);
                        }
                    }
                }
                else if (_currentValue.Contains("-"))
                {
                    var splitted = _currentValue.Split('-');

                    foreach (var item in splitted)
                    {
                        if (item.Any(char.IsDigit))
                        {
                            if (item == splitted.First())
                            {
                                value = System.Convert.ToInt32(item);
                            }
                            else
                            {
                                value += -System.Convert.ToInt32(item);
                            }
                        }
                    }
                }
                else if (_currentValue.Contains("*"))
                {
                    var splitted = _currentValue.Split('*');

                    foreach (var item in splitted)
                    {
                        if (item.Any(char.IsDigit))
                        {
                            if (item == splitted.First())
                            {
                                value = System.Convert.ToInt32(item);
                            }
                            else
                            {
                                value *= System.Convert.ToInt32(item);
                            }
                        }
                    }
                }
                else if (_currentValue.Contains("/"))
                {
                    var splitted = _currentValue.Split('/');

                    foreach (var item in splitted)
                    {
                        if (item.Any(char.IsDigit))
                        {
                            if (item == splitted.First())
                            {
                                value = System.Convert.ToInt32(item);
                            }
                            else
                            {
                                value /= System.Convert.ToInt32(item);
                            }
                        }
                    }
                }
                else if (_currentValue.Any(char.IsDigit))
                {
                    value = System.Convert.ToInt32(_currentValue);
                }

                if (value > 0)
                {
                    _size?.SetValue(value);
                }

                Close();
            }
            catch (System.Exception)
            {
                Wrapper.ShowNotify("Некорректное значение", Constants.AppName);
            }
        }