コード例 #1
0
        public bool TryConvert(TextSlice slice, out Value <TEntity> convertedValue)
        {
            var entity = Convert(slice);

            convertedValue = new ConvertedValue <TEntity>(slice.SourceText, slice.SourceSpan, entity);
            return(true);
        }
コード例 #2
0
        public override void Bind(IntermediateBuilder context)
        {
            _op1.Bind(context);
            _op2.Bind(context);

            CodeType wideType = _op1.Type.GetWiderType(_op2.Type);



            if (wideType is UserType)
            {
                var user     = UserType.ToUserType(wideType);
                var overload = user.GetOperatorOverload(Op, context);

                if (overload != null)
                {
                    _overload = new InterCall(overload, new CodeValue[] { _op1, _op2 }, true);
                    _overload.SetOwner(Owner);
                    _overload.Bind(context);
                    return;
                }
            }

            if (_op1.Type != wideType)
            {
                _op1 = new ConvertedValue(_op1, wideType, Owner); _op1.Bind(context);
            }

            if (_op2.Type != wideType)
            {
                _op2 = new ConvertedValue(_op2, wideType, Owner); _op2.Bind(context);
            }
        }
コード例 #3
0
        public bool TryConvert(TextSlice slice, out Value <TValue> convertedValue)
        {
            Debug.Assert(slice != null);

            convertedValue = new ConvertedValue <TValue>(slice.SourceText, slice.SourceSpan, _valueProvider(slice));
            return(true);
        }
コード例 #4
0
        private void Convert_Click(object sender, RoutedEventArgs e)
        {
            double ConvertedValue;

            if (txtCurrency.Text == null || txtCurrency.Text.Trim() == "")
            {
                MessageBox.Show("Please enter a Currency", "Information", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtCurrency.Focus();
                return;
            }


            if (cmbFromCurrency.SelectedValue == null || cmbFromCurrency.SelectedIndex == 0)
            {
                MessageBox.Show("Please select currency to ", "Information", MessageBoxButton.OK, MessageBoxImage.Warning);
                cmbToCurrency.Focus();
                return;
            }

            if (cmbFromCurrency.Text == cmbToCurrency.Text)
            {
                ConvertedValue      = double.Parse(txtCurrency.Text);
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
            else
            {
                ConvertedValue = (double.Parse(cmbFromCurrency.SelectedValue.ToString()) *
                                  double.Parse(txtCurrency.Text)) /
                                 double.Parse(cmbToCurrency.SelectedValue.ToString());

                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
        }
コード例 #5
0
        private void Convert_Click(object sender, RoutedEventArgs e)
        {
            double ConvertedValue;

            //Check amount textbox is Null or Blank
            if (txtCurrency.Text == null || txtCurrency.Text.Trim() == "")
            {
                //If amount textbox is Null or Blank it will show the below message box
                MessageBox.Show("Please Enter Currency", "Information", MessageBoxButton.OK, MessageBoxImage.Information);

                //After clicking on message box OK sets the Focus on amount textbox
                txtCurrency.Focus();
                return;
            }
            //Else if the currency from is not selected or it is default text --SELECT--
            else if (cmbFromCurrency.SelectedValue == null || cmbFromCurrency.SelectedIndex == 0)
            {
                //It will show the message
                MessageBox.Show("Please Select Currency From", "Information", MessageBoxButton.OK, MessageBoxImage.Information);

                //Set focus on From Combobox
                cmbFromCurrency.Focus();
                return;
            }
            //Else if Currency To is not Selected or Select Default Text --SELECT--
            else if (cmbToCurrency.SelectedValue == null || cmbToCurrency.SelectedIndex == 0)
            {
                //It will show the message
                MessageBox.Show("Please Select Currency To", "Information", MessageBoxButton.OK, MessageBoxImage.Information);

                //Set focus on To Combobox
                cmbToCurrency.Focus();
                return;
            }

            //If From and To Combobox selected values are same
            if (cmbFromCurrency.Text == cmbToCurrency.Text)
            {
                //The amount textbox value set in ConvertedValue.
                //double.parse is used to convert datatype String To Double.
                //Textbox text have string and ConvertedValue is double datatype
                ConvertedValue = double.Parse(txtCurrency.Text);

                //Show in label converted currency and converted currency name.
                // and ToString("N3") is used to place 000 after after the(.)
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
            else
            {
                //Calculation for currency converter is From Currency value multiply(*)
                // with amount textbox value and then the total is divided(/) with To Currency value
                ConvertedValue = (double.Parse(cmbToCurrency.SelectedValue.ToString()) * double.Parse(txtCurrency.Text)) /
                                 double.Parse(cmbFromCurrency.SelectedValue.ToString());

                //Show in label converted currency and converted currency name.
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
        }
コード例 #6
0
        /// <summary>
        /// Gets a named item from the underlying <see cref="ExpandoObject"/>"/>
        /// and applies a <see cref="ValueConverter"/>.
        /// </summary>
        /// <typeparam name="TValue">
        /// The type of value to return.
        /// </typeparam>
        /// </param>
        /// <param name="name">
        /// The name of the item to be returned.
        /// </param>
        /// <param name="valueConverter">
        /// The <see cref="ValueConverter"/> applied to the item identified by
        /// <see cref="name"/>.
        /// </param>
        /// <returns>
        /// A value of type <see cref="TValue"/>.
        /// </returns>
        /// <remarks>
        /// The value returned by this method is stored into underlying <see
        /// cref="ExpandoObject"/> to reduce conversion overhead.
        /// </remarks>
        public TValue GetValue <TValue>(string name, ValueConverter <TValue> valueConverter)
        {
            Contract.Requires <ArgumentNullException>(name != null);
            Contract.Requires <ArgumentNullException>(valueConverter != null);

            if (this.ExpandoObject == null)
            {
                throw new InvalidOperationException(); // TODO: diagnostics
            }

            var    dictionary = (IDictionary <string, object>) this.ExpandoObject;
            object value;

            if (!dictionary.TryGetValue(name, out value) || value == null)
            {
                return(valueConverter.DefaultValue);
            }

            if (value is ConvertedValue)
            {
                return(((ConvertedValue)value).Convert <TValue>(valueConverter));
            }

            // Tradeoff:
            // Risk paying extra for conversion in order to minimize lock time.
            //
            // Rationale:
            // It is unsafe to assume that value converters will not cause
            // problems in a critical section. We only lock on code/data that's
            // under our direct control.

            object convertedValue;
            int    count = 0;

            do
            {
                convertedValue = valueConverter.Convert(value);

                lock (this.gate)
                {
                    value = dictionary[name];

                    if (value is ConvertedValue)
                    {
                        convertedValue = ((ConvertedValue)value).GetAs <TValue>();
                        value          = ((ConvertedValue)value).Get();
                    }
                    else
                    {
                        dictionary[name] = new ConvertedValue(convertedValue);
                    }
                }

                Debug.Assert(++count < 2);
            }while (convertedValue == null);

            return((TValue)convertedValue);
        }
コード例 #7
0
        public string ToString(System.IFormatProvider provider = null)
        {
            if (provider == null)
            {
                provider = System.Globalization.CultureInfo.CurrentCulture;
            }

            return(ConvertedValue.ToString(Format, provider) + " " + UnitName);
        }
コード例 #8
0
        public bool TryConvert(TextSlice slice, out Value <FT> convertedValue)
        {
            Debug.Assert(slice != null);

            string text = slice.Text.ToString();

            convertedValue = new ConvertedValue <FT>(slice.SourceText, slice.SourceSpan, text, text?.Length > 0);
            return(true);
        }
コード例 #9
0
        public bool TryConvert(TextSlice slice, out Value <string> convertedValue)
        {
            Debug.Assert(slice != null);

            string text = slice.Text.ToString();

            convertedValue = new ConvertedValue <string>(slice, text);
            return(true);
        }
コード例 #10
0
        //Convert the button click event
        private void Convert_Click(object sender, RoutedEventArgs e)
        {
            //Create the variable as ConvertedValue with double datatype to store currency converted value
            double ConvertedValue;

            //Check if the amount textbox is Null or Blank
            if (txtCurrency.Text == null || txtCurrency.Text.Trim() == "")
            {
                //If amount textbox is Null or Blank it will show this message box
                MessageBox.Show("Please Enter Currency", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                //After clicking on messagebox OK set focus on amount textbox
                txtCurrency.Focus();
                return;
            }
            //Else if currency From is not selected or select default text --SELECT--
            else if (cmbFromCurrency.SelectedValue == null || cmbFromCurrency.SelectedIndex == 0)
            {
                //Show the message
                MessageBox.Show("Please Select Currency From", "Information", MessageBoxButton.OK, MessageBoxImage.Information);

                //Set focus on the From Combobox
                cmbFromCurrency.Focus();
                return;
            }
            //Else if currency To is not selected or select default text --SELECT--
            else if (cmbToCurrency.SelectedValue == null || cmbToCurrency.SelectedIndex == 0)
            {
                //Show the message
                MessageBox.Show("Please Select Currency To", "Information", MessageBoxButton.OK, MessageBoxImage.Information);

                //Set focus on the To Combobox
                cmbToCurrency.Focus();
                return;
            }

            //Check if From and To Combobox selected values are same
            if (cmbFromCurrency.Text == cmbToCurrency.Text)
            {
                //Amount textbox value set in ConvertedValue.
                //double.parse is used for converting the datatype String To Double.
                //Textbox text have string and ConvertedValue is double Datatype
                ConvertedValue = double.Parse(txtCurrency.Text);
                //Show the label converted currency and converted currency name and ToString("N3") is used to place 000 after the dot(.)
                //3 places of decimal point precision.
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
            else
            {
                //Calculation for currency converter is From Currency value multiply(*)
                //With the amount textbox value and then that total divided(/) with To Currency value
                ConvertedValue = (double.Parse(cmbFromCurrency.SelectedValue.ToString()) * double.Parse(txtCurrency.Text)) / double.Parse(cmbToCurrency.SelectedValue.ToString());

                //Show the label converted currency and converted currency name.
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
        }
コード例 #11
0
        /// <summary>
        /// Gets a named item from the underlying <see cref="Object"/>"/&gt;
        /// and applies a <see cref="ValueConverter&lt;TValue&gt;"/>.
        /// </summary>
        /// <remarks>
        /// The value returned by this method is stored into the backing
        /// <see cref="System.Dynamic.ExpandoObject"/> to reduce conversion overhead.
        /// </remarks>
        /// <typeparam name="TValue">
        /// Type of the value.
        /// </typeparam>
        /// <param name="name">
        /// The name of the item to be returned.
        /// </param>
        /// <param name="valueConverter">
        /// The <see cref="ValueConverter&lt;TValue&gt;"/> applied to the item
        /// identified by <paramref name="name"/>.
        /// </param>
        /// <returns>
        /// A value of type <typeparamref name="TValue"/>.
        /// </returns>
        public TValue GetValue <TValue>(string name, ValueConverter <TValue> valueConverter)
        {
            Contract.Requires <ArgumentNullException>(name != null);
            Contract.Requires <ArgumentNullException>(valueConverter != null);

            var    dictionary = (IDictionary <string, object>) this.Object;
            object value;

            if (!dictionary.TryGetValue(name, out value) || value == null)
            {
                return(valueConverter.DefaultValue);
            }

            var convertedValue = value as ConvertedValue;

            if (convertedValue != null)
            {
                return(convertedValue.Convert <TValue>(valueConverter));
            }

            // Tradeoff:
            // Risk paying extra for conversion in order to minimize lock time.
            //
            // Rationale:
            // It is unsafe to assume that value converters will not cause
            // problems in a critical section. We only lock on code/data that's
            // under our direct control.

            object unconvertedValue;
            int    count = 0;

            do
            {
                unconvertedValue = valueConverter.Convert(value);

                lock (this.gate)
                {
                    value          = dictionary[name];
                    convertedValue = value as ConvertedValue;

                    if (convertedValue != null)
                    {
                        unconvertedValue = convertedValue.GetAs <TValue>();
                        value            = convertedValue.Get();
                    }
                    else
                    {
                        dictionary[name] = new ConvertedValue(unconvertedValue);
                    }
                }

                Debug.Assert(++count < 2, string.Concat("count: ", count));
            }while (unconvertedValue == null);

            return((TValue)unconvertedValue);
        }
コード例 #12
0
        public bool TryConvert(TextSlice slice, out Value <TEntity> convertedValue)
        {
            TEntity entity = _factory.Create();

            for (int i = 0; i < _properties.Length; i++)
            {
                _properties[i].Map(entity, slice);
            }

            convertedValue = new ConvertedValue <TEntity>(slice, entity);
            return(true);
        }
コード例 #13
0
ファイル: Form1.cs プロジェクト: izni-syaz/12_PA09_IZNI
        private void btn_Convert_Click(object sender, EventArgs e)
        {
            double AmountEntered;
            double ConvertedValue;

            //checking for null values
            if ((rdb_USDollar.Checked == false) || (rdb_JapaneseYen.Checked == false))
            {
                txt_ConvertAmount.Text = "Select at least one type of currency to convert";
            }
            try
            {
                //Convert SGD to US dollar
                if (rdb_USDollar.Checked == true)
                {
                    AmountEntered = double.Parse(txt_Amount.Text);
                    ConvertedValue = AmountEntered * 0.74;
                    txt_ConvertAmount.Text = ConvertedValue.ToString();
                }
            }catch(FormatException)
            {
                txt_Amount.Text = "Invalid Amount Input";
                txt_ConvertAmount.Text = "";
            }
            try
            {
                if (rdb_JapaneseYen.Checked == true)
                {
                    AmountEntered = double.Parse(txt_Amount.Text);
                    ConvertedValue = AmountEntered * 81.97;
                    txt_ConvertAmount.Text = ConvertedValue.ToString();
                }
            }catch(FormatException)
            {
                txt_Amount.Text = "Invalid Amount Input";
                txt_ConvertAmount.Text = "";
            }
            try
            {
                if (rdb_MalaysianRinggit.Checked == true)
                {
                    AmountEntered = double.Parse(txt_Amount.Text);
                    ConvertedValue = AmountEntered * 81.97;
                    txt_ConvertAmount.Text = ConvertedValue.ToString();
                }
            }
            catch (FormatException)
            {
                txt_Amount.Text = "Invalid Amount Input";
                txt_ConvertAmount.Text = "";
            }
        }
コード例 #14
0
        public bool TryConvert(TextSlice slice, out Value <Guid> convertedValue)
        {
            Debug.Assert(slice != null);

            if (Guid.TryParse(slice.Text.ToString(), out var value))
            {
                convertedValue = new ConvertedValue <Guid>(slice.SourceText, slice.SourceSpan, value);
                return(true);
            }

            convertedValue = null;
            return(false);
        }
コード例 #15
0
        public bool TryConvert(TextSlice slice, out Value <DateTimeOffset> convertedValue)
        {
            Debug.Assert(slice != null);

            if (DateTimeOffset.TryParse(slice.Text.ToString(), CultureInfo.InvariantCulture, Styles, out var value))
            {
                convertedValue = new ConvertedValue <DateTimeOffset>(slice.SourceText, slice.SourceSpan, value);
                return(true);
            }

            convertedValue = Value.Empty <DateTimeOffset>();
            return(false);
        }
コード例 #16
0
        private void Convert_Click(object sender, RoutedEventArgs e)
        {
            double ConvertedValue;

            if (txtCurrency.Text == null || txtCurrency.Text.Trim() == "")
            {
                MessageBox.Show("Please Enter the amount", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                txtCurrency.Focus();
                return;
            }
            else if (cmbFromCurrency.SelectedValue == null || cmbFromCurrency.SelectedIndex == 0)
            {
                MessageBox.Show("Please select currency from", "Information", MessageBoxButton.OK, MessageBoxImage.Information);

                //Set focus on To Combobox
                cmbFromCurrency.Focus();
                return;
            }
            else if (cmbToCurrency.SelectedValue == null || cmbToCurrency.SelectedIndex == 0)
            {
                //It will show the message
                MessageBox.Show("Please Select Currency To", "Information", MessageBoxButton.OK, MessageBoxImage.Information);

                //Set focus on To Combobox
                cmbToCurrency.Focus();
                return;
            }


            //Check if From and To Combobox selected values are same
            if (cmbFromCurrency.Text == cmbToCurrency.Text)
            {
                //Amount textbox value set in ConvertedValue.
                //double.parse is used for converting the datatype String To Double.
                //Textbox text have string and ConvertedValue is double Datatype
                ConvertedValue = double.Parse(txtCurrency.Text);
                //Show the label converted currency and converted currency name and ToString("N3") is used to place 000 after the dot(.)
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
            else
            {
                //Calculation for currency converter is From Currency value multiply(*)
                //With the amount textbox value and then that total divided(/) with To Currency value
                ConvertedValue = double.Parse(cmbToCurrency.SelectedValue.ToString()) * double.Parse(txtCurrency.Text)
                                 / double.Parse(cmbFromCurrency.SelectedValue.ToString());

                //Show the label converted currency and converted currency name.
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
        }
コード例 #17
0
        public bool TryConvert(TextSlice slice, out Value <decimal> convertedValue)
        {
            Debug.Assert(slice != null);

            decimal value;

            if (decimal.TryParse(slice.Text.ToString(), _styles, CultureInfo.InvariantCulture, out value))
            {
                convertedValue = new ConvertedValue <decimal>(slice, value);
                return(true);
            }

            convertedValue = null;
            return(false);
        }
コード例 #18
0
        public bool TryConvert(TextSlice slice, out Value <DateTimeOffset> convertedValue)
        {
            Debug.Assert(slice != null);

            DateTimeOffset value;

            if (DateTimeOffset.TryParseExact(slice.Text.ToString(), _patterns, CultureInfo.InvariantCulture, Styles, out value))
            {
                convertedValue = new ConvertedValue <DateTimeOffset>(slice, value);
                return(true);
            }

            convertedValue = Value.Invalid <DateTimeOffset>(slice);
            return(false);
        }
コード例 #19
0
        public ConverterViewModelBase()
        {
            Bits = new Bit[MaxDataLength * 8];
            for (var i = 0; i < Bits.Length; i++)
            {
                var bit = new Bit(i, Bytes);
                bit.PropertyChanged      += OnBitChanged;
                Bits[Bits.Length - i - 1] = bit;
            }

            BinaryString  = new ConvertedBinaryString(InvokeOnSTAThread);
            OctalString   = new ConvertedOctalString(InvokeOnSTAThread);
            DecimalString = new ConvertedDecimalString(InvokeOnSTAThread);
            HexString     = new ConvertedHexString(InvokeOnSTAThread);
            AsciiString   = new ConvertedAsciiString(InvokeOnSTAThread);
            Utf8String    = new ConvertedUtf8String(InvokeOnSTAThread);
            Utf32String   = new ConvertedUtf32String(InvokeOnSTAThread);
            UShort        = new ConvertedValue <ushort>(InvokeOnSTAThread);
            Short         = new ConvertedValue <short>(InvokeOnSTAThread);
            UInt          = new ConvertedValue <uint>(InvokeOnSTAThread);
            Int           = new ConvertedValue <int>(InvokeOnSTAThread);
            ULong         = new ConvertedValue <ulong>(InvokeOnSTAThread);
            Long          = new ConvertedValue <long>(InvokeOnSTAThread);
            Float         = new ConvertedValue <float>(InvokeOnSTAThread);
            Double        = new ConvertedValue <double>(InvokeOnSTAThread);
            Decimal       = new ConvertedValue <decimal>(InvokeOnSTAThread);

            BinaryString.OnValueChanged  += OnValueChangedAsync;
            OctalString.OnValueChanged   += OnValueChangedAsync;
            DecimalString.OnValueChanged += OnValueChangedAsync;
            HexString.OnValueChanged     += OnValueChangedAsync;
            AsciiString.OnValueChanged   += OnValueChangedAsync;
            Utf8String.OnValueChanged    += OnValueChangedAsync;
            Utf32String.OnValueChanged   += OnValueChangedAsync;
            UShort.OnValueChanged        += OnValueChangedAsync;
            Short.OnValueChanged         += OnValueChangedAsync;
            UInt.OnValueChanged          += OnValueChangedAsync;
            Int.OnValueChanged           += OnValueChangedAsync;
            ULong.OnValueChanged         += OnValueChangedAsync;
            Long.OnValueChanged          += OnValueChangedAsync;
            Float.OnValueChanged         += OnValueChangedAsync;
            Double.OnValueChanged        += OnValueChangedAsync;
            Decimal.OnValueChanged       += OnValueChangedAsync;

            _surpressUpdates = true;
            Converter        = _converters[0];
            _surpressUpdates = false;
        }
コード例 #20
0
        private void Convert_Click(object sender, RoutedEventArgs e)
        {
            double ConvertedValue;

            //Checking if the currency textbox is empty
            if (txtCurrency.Text == null || txtCurrency.Text.Trim() == "")
            {
                //Error message
                MessageBox.Show("Please enter a value: ", "Information", MessageBoxButton.OK);
                txtCurrency.Focus();
                return;
            }
            //Checking if the From currency combobox has a value that isn't default
            else if (cmbFromCurrency.SelectedValue == null || cmbFromCurrency.SelectedIndex == 0)
            {
                //Error message
                MessageBox.Show("Pleae enter what currency you're converting from", "Information", MessageBoxButton.OK);
                cmbFromCurrency.Focus();
                return;
            }
            //Checking if the To currency combobox has a value that isn't default
            else if (cmbToCurrency.SelectedValue == null || cmbToCurrency.SelectedIndex == 0)
            {
                //Error message
                MessageBox.Show("Please enter to what currency you're converting to", "Information", MessageBoxButton.OK);
                cmbToCurrency.Focus();
                return;
            }
            if (cmbFromCurrency.Text == cmbToCurrency.Text)
            {
                //Here we convert the value which is a string, to a double
                ConvertedValue = double.Parse(txtCurrency.Text);
                //Show the label converted currency and the converted currency's name the N3 is added to add 3 zero's after the .
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
            else
            {
                //Conversion formula
                ConvertedValue = (double.Parse(cmbFromCurrency.SelectedValue.ToString()) *
                                  double.Parse(txtCurrency.Text)) /
                                 double.Parse(cmbToCurrency.SelectedValue.ToString());

                //Displaying the end result
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
        }
コード例 #21
0
        private void btn_Convert_Click(object sender, EventArgs e)
        {
            double AmountEntered;
            double ConvertedValue;

            try
            {
                AmountEntered = double.Parse(txt_Amount.ToString());
            }
            catch (FormatException)
            {
                MessageBox.Show("Please enter numbers only.");
            }

            //checking for null values
            if ((rdb_USD.Checked == false) || (rdb_JPY.Checked == false) || (rdb_MalaysianRinggit.Checked == false))
            {
                txt_ConvertedAmount.Text = "Select at least one type of currency to convert";
            }

            //convert SGD to US Dollars
            if (rdb_USD.Checked == true)
            {
                AmountEntered  = double.Parse(txt_Amount.Text);
                ConvertedValue = AmountEntered * 0.74;

                txt_ConvertedAmount.Text = ConvertedValue.ToString();
            }

            if (rdb_JPY.Checked == true)
            {
                AmountEntered  = double.Parse(txt_Amount.Text);
                ConvertedValue = AmountEntered * 81.97f;

                txt_ConvertedAmount.Text = ConvertedValue.ToString();
            }

            if (rdb_MalaysianRinggit.Checked == true)
            {
                AmountEntered  = double.Parse(txt_Amount.Text);
                ConvertedValue = AmountEntered * 3.01;

                txt_ConvertedAmount.Text = ConvertedValue.ToString();
            }
        }
コード例 #22
0
        private void Convert_Click(object sender, RoutedEventArgs e)
        {
            // store currency converted value
            double ConvertedValue;

            // check if textbox for amount
            if (txtCurrency.Text == null || txtCurrency.Text.Trim() == "")
            {
                // if amount is null or blank, return error to user
                MessageBox.Show("Please enter a value to convert", "Information", MessageBoxButton.OK, MessageBoxImage.Information);

                txtCurrency.Focus();
                return;
            }
            else if (cmbFromCurrency.SelectedValue == null || cmbFromCurrency.SelectedIndex == 0)
            {
                MessageBox.Show("Please select a currency type to convert from.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                cmbFromCurrency.Focus();
                return;
            }
            else if (cmbToCurrency.SelectedValue == null || cmbToCurrency.SelectedIndex == 0)
            {
                MessageBox.Show("Please select a currency to convert to.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                cmbToCurrency.Focus();
                return;
            }

            // check if from and to comboboxes selected values are the same
            if (cmbFromCurrency.Text == cmbToCurrency.Text)
            {
                ConvertedValue = double.Parse(txtCurrency.Text);
                // N3 is used to place 3 zeros after '.'
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
            else
            {
                ConvertedValue = (double.Parse(cmbFromCurrency.SelectedValue.ToString()) *
                                  double.Parse(txtCurrency.Text)) / double.Parse(cmbToCurrency.SelectedValue.ToString());
                // show new currency and converted to name
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
        }
コード例 #23
0
        private void Btn_Convert_Click(object sender, EventArgs e)
        {
            double AmountEntered;
            double ConvertedValue;

            try
            {
                if ((Rdb_USDollars.Checked == false) && (Rdb_JapaneseYen.Checked = false) && (Rdb_MalaysianRinggit.Checked = false))
                {
                    MessageBox.Show("Select at least one type of currency to convert");
                }

                if (Rdb_USDollars.Checked == true)
                {
                    AmountEntered  = double.Parse(Txt_Amount.Text);
                    ConvertedValue = AmountEntered * 0.74;

                    Txt_Value.Text = ConvertedValue.ToString();
                }

                if (Rdb_JapaneseYen.Checked == true)
                {
                    AmountEntered  = double.Parse(Txt_Amount.Text);
                    ConvertedValue = AmountEntered * 81.97;

                    Txt_Value.Text = ConvertedValue.ToString();
                }

                if (Rdb_MalaysianRinggit.Checked == true)
                {
                    AmountEntered  = double.Parse(Txt_Amount.Text);
                    ConvertedValue = AmountEntered * 3.01;

                    Txt_Value.Text = ConvertedValue.ToString();
                }
            }

            catch (FormatException)
            {
                MessageBox.Show("Invalid Input");
            }
        }
コード例 #24
0
        public override void Bind(IntermediateBuilder context)
        {
            foreach (var p in _parameters)
            {
                p.Bind(context);
            }

            _type = context.ResolveType(_typeName);

            _constructor = context.FindMostApplicableConstructor(_type as UserType, _parameters);


            for (int i = 0; i < _parameters.Length; i++)
            {
                if (_parameters[i].Type.CanAssignTo(_constructor.Arguments[i]) == AssignType.CanAssign)
                {
                    continue;
                }

                _parameters[i] = new ConvertedValue(_parameters[i], _constructor.Arguments[i], Owner);
                _parameters[i].Bind(context);
            }
        }
コード例 #25
0
        public bool ConvertTo(PropertyInfo prop, object obj)
        {
            var value = prop.GetValue(obj);

            switch (value)
            {
            case null:
                return(false);

            case int i:
                ConvertedValue = i.ToString();
                return(true);
            }
            var result = value is string;

            if (!result)
            {
                return(false);
            }
            ConvertedValue = (string)value;
            ConvertedValue = ConvertedValue?.Trim();
            return(true);
        }
コード例 #26
0
        private void Convert_Click(object sender, RoutedEventArgs e)
        {
            double ConvertedValue;

            if (txtCurrency.Text == null || txtCurrency.Text.Trim() == "")
            {
                MessageBox.Show("Please Enter Currency", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                txtCurrency.Focus();
                return;
            }
            //Else if currency From is not selected or select default text --SELECT--
            else if (cmbFromCurrency.SelectedValue == null || cmbFromCurrency.SelectedIndex == 0)
            {
                MessageBox.Show("Please Select Currency From", "Information", MessageBoxButton.OK, MessageBoxImage.Information)
                cmbFromCurrency.Focus();
                return;
            }
            // Else if currency To is not selected or select default text --SELECT--
            else if (cmbToCurrency.SelectedValue == null || cmbToCurrency.SelectedIndex == 0)
            {
                MessageBox.Show("Please Select Currency To", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                cmbToCurrency.Focus();
                return;
            }

            //If From and To Combobox selects same value
            if (cmbFromCurrency.Text == cmbToCurrency.Text)
            {
                ConvertedValue      = double.Parse(txtCurrency.Text);
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N2");
            }
            else
            {
                ConvertedValue      = (double.Parse(cmbFromCurrency.SelectedValue.ToString()) * double.Parse(txtCurrency.Text)) / double.Parse(cmbToCurrency.SelectedValue.ToString());
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N2");
            }
        }
コード例 #27
0
        private void Convert_Click(object sender, RoutedEventArgs e)
        {
            double ConvertedValue;

            //Check amount textbox is Null or Blank
            if (txtCurrency.Text == null || txtCurrency.Text.Trim() == "")
            {
                MessageBox.Show("Please Enter Currency", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                txtCurrency.Focus();
                return;
            }
            else if (cmbToCurrency.SelectedValue == null || cmbToCurrency.SelectedIndex == 0)
            {
                MessageBox.Show("Please Select Currency To", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                cmbToCurrency.Focus();
                return;
            }

            if (cmbFromCurrency.Text == cmbToCurrency.Text)
            {
                ConvertedValue = double.Parse(txtCurrency.Text);

                //Show in label converted currency and converted currency name.
                // and ToString("N3") is used to place 000 after after the(.)
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
            else
            {
                //Calculation for currency converter is From Currency value multiply(*)
                // with amount textbox value and then the total is divided(/) with To Currency value
                ConvertedValue = (double.Parse(cmbToCurrency.SelectedValue.ToString()) * double.Parse(txtCurrency.Text)) / double.Parse(cmbFromCurrency.SelectedValue.ToString());

                //Show in label converted currency and converted currency name.
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
        }
コード例 #28
0
ファイル: InterCall.cs プロジェクト: Etny/RedmondCompiler
        public override void Bind(IntermediateBuilder context)
        {
            if (_method == null)
            {
                foreach (var p in _parameters)
                {
                    p.Bind(context);
                }

                _thisPtr?.Bind(context);

                if (_resolver != null)
                {
                    _resolver.SetOwner(Owner);
                    _resolver.Bind(context);
                    _staticCall = _resolver.IsStatic;
                    if (!_staticCall)
                    {
                        _thisPtr = _resolver.GetReferencedFieldOrProperty();
                    }
                }

                CodeType type;
                if (_staticCall)
                {
                    type = _resolver.Type;
                }
                else if (_thisPtr == null)
                {
                    if (!_baseAccess)
                    {
                        type = new InterUserType(Owner.Owner);
                    }
                    else
                    {
                        type = UserType.ToUserType(Owner.Owner.BaseType);
                    }
                }
                else
                {
                    if (!_baseAccess)
                    {
                        type = _thisPtr.Type;
                    }
                    else
                    {
                        type = UserType.ToUserType(_thisPtr.Type).GetBaseType();
                    }
                }

                CodeType searchType;

                if (ThisPointerTypeOverride != null)
                {
                    searchType = ThisPointerTypeOverride;
                }
                else if (ThisPointerTypeNameOverride != TypeName.Unknown)
                {
                    searchType = context.ResolveType(ThisPointerTypeNameOverride);
                }
                else
                {
                    searchType = type;
                }

                _method = context.FindClosestFunction(_targetName, searchType, _parameters);
            }

            _return = _method.ReturnType;

            for (int i = 0; i < _parameters.Length; i++)
            {
                if (_parameters[i].Type.CanAssignTo(_method.Arguments[i].StoredType) == AssignType.CanAssign)
                {
                    continue;
                }

                _parameters[i] = new ConvertedValue(_parameters[i], _method.Arguments[i].StoredType, Owner);
                _parameters[i].Bind(context);
            }

            _valueType = _thisPtr != null &&
                         ((_thisPtr.Type is UserType &&
                           (_thisPtr.Type as UserType).ValueType) ||
                          _thisPtr.IsSymbol() && _thisPtr.Type is BasicType);

            if (_thisPtr == null)
            {
                return;
            }
            if (_thisPtr.Type is UserType && (_thisPtr.Type as UserType).ValueType)
            {
                _valueType = true;
            }
            if (_method.IsInstance && !_thisPtr.IsSymbol() && _thisPtr.Type is BasicType)
            {
                if (_thisPtr.ToSymbol() == null)
                {
                    _valueType = true;
                    LocalSymbol l = new LocalSymbol("locl" + Owner.Locals.Count, _thisPtr.Type, Owner.Locals.Count);
                    Owner.Locals.Add(l);
                    _symbolConversion = new InterCopy(l, _thisPtr);
                    _symbolConversion.SetOwner(Owner);
                    _symbolConversion.Bind(context);
                    _thisPtr = l;
                }
                else
                {
                    _thisPtr = _thisPtr.ToSymbol();
                }
            }
        }