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");
            }
        }
Beispiel #2
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");
            }
        }
Beispiel #3
0
        public string ToString(System.IFormatProvider provider = null)
        {
            if (provider == null)
            {
                provider = System.Globalization.CultureInfo.CurrentCulture;
            }

            return(ConvertedValue.ToString(Format, provider) + " " + UnitName);
        }
        //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");
            }
        }
Beispiel #5
0
        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 = "";
            }
        }
Beispiel #6
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");
            }
        }
        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");
            }
        }
Beispiel #8
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();
            }
        }
        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 amount", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                txtCurrency.Focus();
                return;
            }

            // Check FROM cmb is selected or not
            else if (cmbFromCurrency.SelectedValue == null || cmbFromCurrency.SelectedIndex == 0)
            {
                MessageBox.Show("Please select a currency you want to convert from", "Information", MessageBoxButton.OK, MessageBoxImage.Information);

                // Set focus on From cmb
                cmbFromCurrency.Focus();
                return;
            }

            // Check To cmb is selected or not
            else if (cmbToCurrency.SelectedValue == null || cmbToCurrency.SelectedIndex == 0)
            {
                MessageBox.Show("Please select a currency you want to convert to", "Information", MessageBoxButton.OK, MessageBoxImage.Information);

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

            if (cmbFromCurrency.Text == cmbToCurrency.Text)
            {
                ConvertedValue      = double.Parse(txtCurrency.Text);
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
            else
            {
                ConvertedValue      = (double.Parse(cmbToCurrency.SelectedValue.ToString()) * double.Parse(txtCurrency.Text)) / double.Parse(cmbFromCurrency.SelectedValue.ToString());
                lblCurrency.Content = cmbToCurrency.Text + " " + ConvertedValue.ToString("N3");
            }
        }
Beispiel #10
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");
            }
        }
Beispiel #11
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");
            }
        }
Beispiel #12
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");
            }
        }
        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");
            }
        }