@ -1,19 +1,54 @@
using BookAStar.Attributes ;
using BookAStar.Interfaces ;
using BookAStar.Model.Workflow ;
using BookAStar.ViewModels.Validation ;
using System ;
using System.Globalization ;
using System.Windows.Input ;
using System.ComponentModel ;
namespace BookAStar.ViewModels.EstimateAndBilling
{
public class BillingLineViewModel : EditingViewModel , IBillingLine
public class BillingLineViewModel : EditingViewModel <BillingLine > , IBillingLine
{
BillingLine data ;
public ICommand RemoveCommand { get ; set ; }
public ICommand ValidateCommand { set ; get ; }
public BillingLineViewModel ( BillingLine data )
public BillingLineViewModel ( BillingLine data ) : base ( data )
{
this . Data = data ;
CheckCommand = new Action < BillingLine , ModelState > (
( l , s ) = > {
if ( string . IsNullOrWhiteSpace ( l . Description ) )
{
s . AddError ( "Description" , Strings . NoDescription ) ;
}
if ( l . UnitaryCost < 0 ) { s . AddError ( "UnitaryCost" , Strings . InvalidValue ) ; }
if ( l . Count < 0 ) { s . AddError ( "Count" , Strings . InvalidValue ) ; }
} ) ;
SyncData ( ) ;
}
private void SyncData ( )
{
if ( Data ! = null )
{
// set durationValue, durationUnit
Duration = Data . Duration ;
// other redondant representation
count = Data . Count ;
description = Data . Description ;
unitaryCostText = Data . UnitaryCost . ToString ( "G" , CultureInfo . InvariantCulture ) ;
}
CheckCommand ( Data , ViewModelState ) ;
}
protected override void OnPropertyChanged ( PropertyChangedEventArgs e )
{
base . OnPropertyChanged ( e ) ;
if ( e . PropertyName = = "Data" )
{
SyncData ( ) ;
}
}
private int count ;
@ -27,7 +62,7 @@ namespace BookAStar.ViewModels.EstimateAndBilling
set
{
SetProperty < int > ( ref count , value ) ;
d ata. Count = count ;
D ata. Count = count ;
}
}
private string description ;
@ -41,10 +76,10 @@ namespace BookAStar.ViewModels.EstimateAndBilling
set
{
SetProperty < string > ( ref description , value ) ;
data . Description = description ;
IsValid = ! string . IsNullOrWhiteSpace ( description ) ;
Data . Description = description ;
}
}
decimal unitaryCost ;
public decimal UnitaryCost
{
@ -56,7 +91,7 @@ namespace BookAStar.ViewModels.EstimateAndBilling
set
{
SetProperty < decimal > ( ref unitaryCost , value ) ;
d ata. UnitaryCost = unitaryCost ;
D ata. UnitaryCost = unitaryCost ;
}
}
@ -71,7 +106,7 @@ namespace BookAStar.ViewModels.EstimateAndBilling
set
{
SetProperty < int > ( ref durationValue , value , "DurationValue" ) ;
d ata. Duration = this . Duration ;
D ata. Duration = this . Duration ;
}
}
@ -94,7 +129,7 @@ pour décrire la quantité de travail associée à ce type de service")]
set
{
SetProperty < DurationUnits > ( ref durationUnit , value , "DurationUnit" ) ;
d ata. Duration = this . Duration ;
D ata. Duration = this . Duration ;
}
}
@ -120,7 +155,6 @@ pour décrire la quantité de travail associée à ce type de service")]
}
}
public ICommand ValidateCommand { set ; get ; }
public TimeSpan Duration
{
@ -161,26 +195,5 @@ pour décrire la quantité de travail associée à ce type de service")]
}
}
public BillingLine Data
{
get
{
return data ;
}
set
{
SetProperty < BillingLine > ( ref data , value ) ;
if ( data ! = null )
{
// sets durationValue & durationUnit
count = data . Count ;
description = data . Description ;
Duration = data . Duration ;
unitaryCostText = data . UnitaryCost . ToString ( "G" , CultureInfo . InvariantCulture ) ;
}
}
}
}
}