- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Data;
- using System.Text.RegularExpressions;
- namespace StaticCurrencyConverter
- {
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- Currency();
- }
- private void Currency()
- {
- //membuat tabel untuk list mata uang
- DataTable dataCurrency = new DataTable();
- //menambah isi kolom
- dataCurrency.Columns.Add("MataUang");
- dataCurrency.Columns.Add("Nilai");
- //menambah isi baris
- dataCurrency.Rows.Add("RUPIAH", 1);
- dataCurrency.Rows.Add("YEN", 134); //1 yen = 134 rupiah
- dataCurrency.Rows.Add("USD", 14560); //1 dolar = 14.560 rupiah
- //Memasukkan data ke combo box From
- combo1.ItemsSource = dataCurrency.DefaultView;
- combo1.DisplayMemberPath = "MataUang";
- combo1.SelectedValuePath = "Nilai";
- //Memasukkan data ke combo box To
- combo2.ItemsSource = dataCurrency.DefaultView;
- combo2.DisplayMemberPath = "MataUang";
- combo2.SelectedValuePath = "Nilai";
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- double ConvertedValue;
- //kasus ketika bagian 'Amount' masih kosong
- if(textamount.Text == null || textamount.Text.Trim() == "")
- {
- MessageBox.Show("Please input the amount you want", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
- textamount.Focus();
- return;
- }
- //kasus ketika mata uang di 'From' belum dipilih
- else if (combo1.Text == null || combo1.Text.Trim() == "")
- {
- MessageBox.Show("Please Choose The Currency You Want To Convert From", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
- combo1.Focus();
- return;
- }
- //kasus ketika mata uang di 'To' belum dipilih
- else if(combo2.Text == null || combo2.Text.Trim() == "")
- {
- MessageBox.Show("Please Choose The Currency You Want To Convert To", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
- combo2.Focus();
- return;
- }
- //kasus ketika mata uang di 'From' sama dengan mata uang di 'To'
- if (combo1.Text == combo2.Text)
- {
- ConvertedValue = double.Parse(textamount.Text);
- resulttext.Content = textamount.Text + " " + combo1.Text + " " + ":" + " " + ConvertedValue.ToString() + " " + combo2.Text;
- }
- //ketika semua sudah diisi, diproses menggunakan perhitungan di bawah
- else
- {
- ConvertedValue = (double.Parse(combo1.SelectedValue.ToString()) * double.Parse(textamount.Text)) / double.Parse(combo2.SelectedValue.ToString());
- resulttext.Content = textamount.Text + " " + combo1.Text + " " + ":" + " " + ConvertedValue.ToString() + " " + combo2.Text;
- }
- }
- }
- }