new files, fixes recent refactorings and more
This commit is contained in:
parent
bfaa70f1a6
commit
f9bd1c2511
14 changed files with 200 additions and 130 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using BookAStar.Interfaces;
|
||||
using BookAStar.Model.Workflow;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Input;
|
||||
using Xamarin.Forms;
|
||||
using XLabs.Forms.Mvvm;
|
||||
|
|
@ -10,18 +11,12 @@ namespace BookAStar.ViewModels
|
|||
public class BillingLineViewModel : ViewModel, IBillingLine
|
||||
{
|
||||
BillingLine data;
|
||||
public Estimate Billing { protected set; get; }
|
||||
|
||||
public BillingLineViewModel(Estimate billing, BillingLine data)
|
||||
public BillingLineViewModel( BillingLine data)
|
||||
{
|
||||
this.data = (data == null) ? new BillingLine() : data;
|
||||
Billing = billing;
|
||||
ValidateCommand =
|
||||
new Command(
|
||||
() => {
|
||||
Billing.Bill.Add(data);
|
||||
Validated.Invoke(this, new EventArgs());
|
||||
});
|
||||
// sets durationValue & unit
|
||||
Duration = data.Duration;
|
||||
}
|
||||
|
||||
protected int count;
|
||||
|
|
@ -29,12 +24,13 @@ namespace BookAStar.ViewModels
|
|||
{
|
||||
get
|
||||
{
|
||||
return count;
|
||||
return data.Count;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
SetProperty<int>(ref count, value, "Count");
|
||||
data.Count = count;
|
||||
}
|
||||
}
|
||||
protected string description;
|
||||
|
|
@ -42,45 +38,129 @@ namespace BookAStar.ViewModels
|
|||
{
|
||||
get
|
||||
{
|
||||
return description;
|
||||
return data.Description;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
SetProperty<string>(ref description, value, "Description");
|
||||
data.Description = value;
|
||||
}
|
||||
}
|
||||
protected TimeSpan duration;
|
||||
public TimeSpan Duration
|
||||
protected int durationValue;
|
||||
public int DurationValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return duration;
|
||||
return durationValue;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
SetProperty<TimeSpan>(ref duration, value, "Duration");
|
||||
SetProperty<int>(ref durationValue, value, "DurationValue");
|
||||
data.Duration = this.Duration;
|
||||
}
|
||||
}
|
||||
|
||||
public enum DurationUnits:int
|
||||
{
|
||||
Jours=0,
|
||||
Heures=1,
|
||||
Minutes=2
|
||||
}
|
||||
private DurationUnits durationUnit;
|
||||
public DurationUnits DurationUnit
|
||||
{
|
||||
get {
|
||||
return durationUnit;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty<DurationUnits>(ref durationUnit, value, "DurationUnit");
|
||||
data.Duration = this.Duration;
|
||||
}
|
||||
}
|
||||
|
||||
protected decimal unitaryCost;
|
||||
public decimal UnitaryCost
|
||||
public static readonly string unitCostFormat = "0,.00";
|
||||
public string UnitaryCostText
|
||||
{
|
||||
get
|
||||
{
|
||||
return unitaryCost;
|
||||
return unitaryCost.ToString(unitCostFormat, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
SetProperty<decimal>(ref unitaryCost, value, "UnitaryCost");
|
||||
decimal newValue;
|
||||
if (decimal.TryParse(value, NumberStyles.Currency,
|
||||
CultureInfo.InvariantCulture,
|
||||
out newValue))
|
||||
{
|
||||
SetProperty<decimal>(ref unitaryCost, newValue, "UnitaryCostText");
|
||||
SetProperty<bool>(ref invalidCost, false, "InvalidCost");
|
||||
}
|
||||
else
|
||||
SetProperty<bool>(ref invalidCost, true, "InvalidCost");
|
||||
}
|
||||
}
|
||||
bool invalidCost;
|
||||
public bool InvalidCost
|
||||
{
|
||||
get { return invalidCost; }
|
||||
}
|
||||
public ICommand ValidateCommand { set; get; }
|
||||
|
||||
public TimeSpan Duration
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (DurationUnit)
|
||||
{
|
||||
case DurationUnits.Heures:
|
||||
return new TimeSpan(DurationValue, 0, 0);
|
||||
case DurationUnits.Jours:
|
||||
return new TimeSpan(DurationValue*24, 0, 0);
|
||||
case DurationUnits.Minutes:
|
||||
return new TimeSpan(0, DurationValue, 0);
|
||||
// Assert(false); since all units are treated bellow
|
||||
default:
|
||||
return new TimeSpan(0, 0, DurationValue);
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
double days = value.TotalDays;
|
||||
if (days >= 1.0)
|
||||
{
|
||||
DurationValue = (int) days;
|
||||
DurationUnit = DurationUnits.Jours;
|
||||
return;
|
||||
}
|
||||
double hours = value.TotalHours;
|
||||
if (hours >= 1.0)
|
||||
{
|
||||
DurationValue = (int) hours;
|
||||
DurationUnit = DurationUnits.Jours;
|
||||
return;
|
||||
}
|
||||
DurationValue = (int) value.TotalMinutes;
|
||||
DurationUnit = DurationUnits.Minutes;
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand ValidateCommand { protected set; get; }
|
||||
|
||||
public event EventHandler<EventArgs> Validated;
|
||||
public decimal UnitaryCost
|
||||
{
|
||||
get
|
||||
{
|
||||
return decimal.Parse(this.UnitaryCostText,CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
UnitaryCostText = value.ToString(unitCostFormat, CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ using XLabs.Platform.Services;
|
|||
|
||||
namespace BookAStar.ViewModels
|
||||
{
|
||||
|
||||
internal class DashboardViewModel : ViewModel
|
||||
{
|
||||
public string UserId
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue