yavsc/BookAStar/BookAStar/ViewModels/Estimate/EditEstimateViewModel.cs

128 lines
3.8 KiB
C#
Raw Normal View History

2016-10-02 19:39:22 +02:00
using System.Collections.Generic;
2016-09-29 04:54:14 +02:00
using BookAStar.Model.Workflow;
using System.Collections.ObjectModel;
using BookAStar.Model;
2016-10-03 18:10:39 +02:00
using Xamarin.Forms;
2016-10-18 15:51:56 +02:00
using BookAStar.Data;
using Newtonsoft.Json;
2016-09-29 04:54:14 +02:00
namespace BookAStar.ViewModels
{
2016-10-18 15:51:56 +02:00
public class EditEstimateViewModel : EditingViewModel
2016-09-29 04:54:14 +02:00
{
2016-10-18 15:51:56 +02:00
/// <summary>
/// For deserialization
/// </summary>
public EditEstimateViewModel()
{
}
/// <summary>
/// Builds a new view model on estimate,
/// sets <c>Data</c> with given value parameter
/// </summary>
/// <param name="data"></param>
/// <param name="localState"></param>
public EditEstimateViewModel(Estimate data, LocalState localState )
2016-09-29 04:54:14 +02:00
{
2016-10-03 18:10:39 +02:00
Data = data;
2016-10-18 15:51:56 +02:00
State = localState;
2016-10-13 16:19:28 +02:00
}
private void Bill_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
2016-11-10 12:26:55 +01:00
Data.Bill = new List<BillingLine>( Bill );
2016-10-13 16:19:28 +02:00
NotifyPropertyChanged("FormattedTotal");
2016-09-29 04:54:14 +02:00
}
2016-10-18 15:51:56 +02:00
private Estimate data;
public Estimate Data { get { return data; } set {
data = value;
if (data.AttachedFiles == null) data.AttachedFiles = new List<string>();
if (data.AttachedGraphics == null) data.AttachedGraphics = new List<string>();
if (data.Bill == null) data.Bill = new List<BillingLine>();
AttachedFiles = new ObservableCollection<string>(data.AttachedFiles);
AttachedGraphicList = new ObservableCollection<string>(data.AttachedGraphics);
Bill = new ObservableCollection<BillingLine>(data.Bill);
Bill.CollectionChanged += Bill_CollectionChanged;
} }
[JsonIgnore]
2016-09-29 04:54:14 +02:00
public ObservableCollection<string> AttachedFiles
{
get; protected set;
}
2016-10-18 15:51:56 +02:00
[JsonIgnore]
2016-09-29 04:54:14 +02:00
public ObservableCollection<string> AttachedGraphicList
{
get; protected set;
}
2016-10-18 15:51:56 +02:00
[JsonIgnore]
2016-09-29 04:54:14 +02:00
public ObservableCollection<BillingLine> Bill
{
get; protected set;
}
2016-10-03 18:10:39 +02:00
string newDesc;
2016-10-18 15:51:56 +02:00
[JsonIgnore]
2016-09-29 04:54:14 +02:00
public string Description
{
get
{
2016-10-03 18:10:39 +02:00
return Data.Description;
2016-09-29 04:54:14 +02:00
}
set
{
2016-10-03 18:10:39 +02:00
SetProperty<string>(ref newDesc, value, "Description");
Data.Description = newDesc;
2016-09-29 04:54:14 +02:00
}
}
private string title;
2016-10-18 15:51:56 +02:00
[JsonIgnore]
2016-09-29 04:54:14 +02:00
public string Title
{
get
{
2016-10-03 18:10:39 +02:00
return Data.Title;
2016-09-29 04:54:14 +02:00
}
set
{
SetProperty<string>(ref title, value, "Title");
2016-10-03 18:10:39 +02:00
Data.Title = title;
2016-09-29 04:54:14 +02:00
}
}
2016-10-18 15:51:56 +02:00
[JsonIgnore]
2016-10-03 18:10:39 +02:00
public ClientProviderInfo Client { get { return Data.Client; } }
2016-10-18 15:51:56 +02:00
[JsonIgnore]
2016-10-03 18:10:39 +02:00
public BookQueryData Query { get { return Data.Query; } }
2016-10-18 15:51:56 +02:00
[JsonIgnore]
2016-10-03 18:10:39 +02:00
public FormattedString FormattedTotal
{
get
{
OnPlatform<Font> lfs = (OnPlatform<Font>)App.Current.Resources["LargeFontSize"];
OnPlatform<Color> etc = (OnPlatform<Color>)App.Current.Resources["EmphasisTextColor"];
2016-09-29 04:54:14 +02:00
2016-10-03 18:10:39 +02:00
return new FormattedString
{
2016-09-29 04:54:14 +02:00
2016-10-03 18:10:39 +02:00
Spans = {
new Span { Text = "Total TTC: " },
new Span { Text = Data.Total.ToString(),
ForegroundColor = etc.Android ,
FontSize = (double) lfs.Android.FontSize },
new Span { Text = "€", FontSize = (double) lfs.Android.FontSize }
}
};
}
}
2016-09-29 04:54:14 +02:00
}
}