This paste brought to you by Pastebin. View Raw

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System.Data;
  16. using System.Text.RegularExpressions;
  17.  
  18. namespace StaticCurrencyConverter
  19. {
  20.     public partial class MainWindow : Window
  21.     {
  22.         public MainWindow()
  23.         {
  24.             InitializeComponent();
  25.             Currency();
  26.         }
  27.  
  28.         private void Currency()
  29.         {
  30.             //membuat tabel untuk list mata uang
  31.             DataTable dataCurrency = new DataTable();
  32.  
  33.             //menambah isi kolom
  34.             dataCurrency.Columns.Add("MataUang");
  35.             dataCurrency.Columns.Add("Nilai");
  36.  
  37.             //menambah isi baris
  38.             dataCurrency.Rows.Add("RUPIAH", 1);
  39.             dataCurrency.Rows.Add("YEN", 134); //1 yen = 134 rupiah
  40.             dataCurrency.Rows.Add("USD", 14560); //1 dolar = 14.560 rupiah
  41.  
  42.             //Memasukkan data ke combo box From
  43.             combo1.ItemsSource = dataCurrency.DefaultView;
  44.             combo1.DisplayMemberPath = "MataUang";
  45.             combo1.SelectedValuePath = "Nilai";
  46.  
  47.             //Memasukkan data ke combo box To
  48.             combo2.ItemsSource = dataCurrency.DefaultView;
  49.             combo2.DisplayMemberPath = "MataUang";
  50.             combo2.SelectedValuePath = "Nilai";
  51.         }
  52.  
  53.         private void Button_Click(object sender, RoutedEventArgs e)
  54.         {
  55.             double ConvertedValue;
  56.  
  57.             //kasus ketika bagian 'Amount' masih kosong
  58.             if(textamount.Text == null || textamount.Text.Trim() == "")
  59.             {
  60.                 MessageBox.Show("Please input the amount you want", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
  61.                 textamount.Focus();
  62.                 return;
  63.             }
  64.  
  65.             //kasus ketika mata uang di 'From' belum dipilih
  66.             else if (combo1.Text == null || combo1.Text.Trim() == "")
  67.             {
  68.                 MessageBox.Show("Please Choose The Currency You Want To Convert From", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
  69.                 combo1.Focus();
  70.                 return;
  71.             }
  72.  
  73.             //kasus ketika mata uang di 'To' belum dipilih
  74.             else if(combo2.Text == null || combo2.Text.Trim() == "")
  75.             {
  76.                 MessageBox.Show("Please Choose The Currency You Want To Convert To", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
  77.                 combo2.Focus();
  78.                 return;
  79.             }
  80.  
  81.             //kasus ketika mata uang di 'From' sama dengan mata uang di 'To'
  82.             if (combo1.Text == combo2.Text)
  83.             {
  84.                 ConvertedValue = double.Parse(textamount.Text);
  85.                 resulttext.Content = textamount.Text + " " + combo1.Text + "   " + ":" + "   " + ConvertedValue.ToString() + " " + combo2.Text;
  86.             }
  87.  
  88.             //ketika semua sudah diisi, diproses menggunakan perhitungan di bawah
  89.             else
  90.             {
  91.                 ConvertedValue = (double.Parse(combo1.SelectedValue.ToString()) * double.Parse(textamount.Text)) / double.Parse(combo2.SelectedValue.ToString());
  92.                 resulttext.Content = textamount.Text + " " + combo1.Text + "   " + ":" + "   " + ConvertedValue.ToString() + " " + combo2.Text;
  93.             }
  94.         }
  95.     }
  96. }