Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.ComponentModel;
  6.  
  7. namespace LatihanMVVM
  8. {
  9.     class ItemPenjualanViewModel : INotifyPropertyChanged
  10.     {
  11.         public event PropertyChangedEventHandler PropertyChanged;
  12.  
  13.         private ItemPenjualan model;
  14.  
  15.         public ItemPenjualanViewModel(ItemPenjualan itemPenjualan = null)
  16.         {
  17.             this.model = itemPenjualan ?? new ItemPenjualan();
  18.         }
  19.  
  20.         public string NamaBarang
  21.         {
  22.             get { return model.NamaBarang; }
  23.             set
  24.             {
  25.                 if (value != model.NamaBarang)
  26.                 {
  27.                     model.NamaBarang = value;
  28.                     PropertyChanged(this, new PropertyChangedEventArgs("NamaBarang"));
  29.                 }
  30.             }
  31.         }
  32.  
  33.         public int Jumlah
  34.         {
  35.             get { return model.Jumlah; }
  36.             set
  37.             {
  38.                 if (value != model.Jumlah)
  39.                 {
  40.                     model.Jumlah = value;
  41.                     PropertyChanged(this, new PropertyChangedEventArgs("Jumlah"));
  42.                     PropertyChanged(this, new PropertyChangedEventArgs("Total"));
  43.                 }
  44.             }
  45.         }
  46.  
  47.         public decimal Harga
  48.         {
  49.             get { return model.Harga; }
  50.             set
  51.             {
  52.                 if (value != model.Harga)
  53.                 {
  54.                     model.Harga = value;
  55.                     PropertyChanged(this, new PropertyChangedEventArgs("Harga"));
  56.                     PropertyChanged(this, new PropertyChangedEventArgs("Total"));
  57.                 }
  58.             }
  59.         }
  60.  
  61.         public decimal DiskonPersen
  62.         {
  63.             get { return model.DiskonPersen; }
  64.             set
  65.             {
  66.                 if (value != model.DiskonPersen)
  67.                 {
  68.                     model.DiskonPersen = value;
  69.                     PropertyChanged(this, new PropertyChangedEventArgs("DiskonPersen"));
  70.                     PropertyChanged(this, new PropertyChangedEventArgs("Total"));
  71.                 }
  72.             }
  73.         }
  74.  
  75.         public string Total
  76.         {
  77.             get
  78.             {
  79.                 decimal? total = model.Total();
  80.                 if (!total.HasValue)
  81.                 {
  82.                     return "-";
  83.                 }
  84.                 else
  85.                 {
  86.                     return total.Value.ToString("C");
  87.                 }
  88.             }
  89.         }
  90.  
  91.         public ItemPenjualan Model
  92.         {
  93.             get { return this.model; }
  94.         }
  95.     }
  96. }