validation
This commit is contained in:
parent
f79502bdfe
commit
8db905a90e
4 changed files with 48 additions and 17 deletions
|
|
@ -100,7 +100,7 @@
|
|||
<StackLayout Orientation="Vertical">
|
||||
<Button Text="Ajouter une ligne de facture" Clicked="OnNewCommanLine"></Button>
|
||||
<Label FormattedText="{Binding FormattedTotal}"/>
|
||||
<Button Text="Valider ce devis" Clicked="OnEstimateValidated" ></Button>
|
||||
<Button x:Name="btnValidate" Text="Valider ce devis" Clicked="OnEstimateValidated" IsEnabled="{Binding ViewModelState.IsValid}" ></Button>
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
|
|
|
|||
|
|
@ -11,11 +11,29 @@ namespace BookAStar.Pages
|
|||
|
||||
public partial class EditEstimatePage : ContentPage
|
||||
{
|
||||
|
||||
public EditEstimateViewModel Model
|
||||
{
|
||||
get
|
||||
{
|
||||
return (EditEstimateViewModel)BindingContext;
|
||||
}
|
||||
}
|
||||
public EditEstimatePage(EditEstimateViewModel model)
|
||||
{
|
||||
InitializeComponent();
|
||||
BindingContext = model;
|
||||
Model.CheckCommand = new Action<Estimate, ViewModels.Validation.ModelState>(
|
||||
(e, m) =>
|
||||
{
|
||||
foreach (var line in model.Bill)
|
||||
{
|
||||
line.Check();
|
||||
if (!line.ViewModelState.IsValid)
|
||||
model.ViewModelState.AddError("Bill", "invalid line");
|
||||
}
|
||||
});
|
||||
|
||||
InitializeComponent();
|
||||
Model.Check();
|
||||
}
|
||||
|
||||
protected override void OnBindingContextChanged()
|
||||
|
|
@ -56,27 +74,32 @@ namespace BookAStar.Pages
|
|||
}
|
||||
protected void OnEditLine(object sender, ItemTappedEventArgs e)
|
||||
{
|
||||
|
||||
var line = (BillingLineViewModel)e.Item;
|
||||
var evm = ((EditEstimateViewModel)BindingContext);
|
||||
// update the validation command, that
|
||||
// was creating a new line in the bill at creation time,
|
||||
// now one only wants to update the line
|
||||
line.ValidateCommand = new Command(() =>
|
||||
{
|
||||
evm.Check();
|
||||
DataManager.Current.EstimationCache.SaveEntity();
|
||||
});
|
||||
// and setup a removal command, that was not expected at creation time
|
||||
var evm = (EditEstimateViewModel)BindingContext;
|
||||
line.RemoveCommand = new Command(() =>
|
||||
{
|
||||
evm.Bill.Remove(line);
|
||||
evm.Check();
|
||||
DataManager.Current.EstimationCache.SaveEntity();
|
||||
});
|
||||
App.NavigationService.NavigateTo<EditBillingLinePage>(
|
||||
true, line );
|
||||
BillListView.SelectedItem = null;
|
||||
}
|
||||
|
||||
protected async void OnEstimateValidated(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
var thisPage = this;
|
||||
var evm = (EditEstimateViewModel) BindingContext;
|
||||
var cmd = new Command<bool>( async (validated) =>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,15 @@ namespace BookAStar.ViewModels.EstimateAndBilling
|
|||
{
|
||||
SyncData();
|
||||
}
|
||||
|
||||
public override void OnViewAppearing()
|
||||
{
|
||||
base.OnViewAppearing();
|
||||
SyncData();
|
||||
}
|
||||
/// <summary>
|
||||
/// Called to synchronyze this view on target model,
|
||||
/// at accepting a new representation for this model
|
||||
/// </summary>
|
||||
private void SyncData()
|
||||
{
|
||||
if (Data.AttachedFiles == null) Data.AttachedFiles = new List<string>();
|
||||
|
|
@ -41,12 +49,13 @@ namespace BookAStar.ViewModels.EstimateAndBilling
|
|||
NotifyPropertyChanged("FormattedTotal");
|
||||
NotifyPropertyChanged("Query");
|
||||
NotifyPropertyChanged("CLient");
|
||||
NotifyPropertyChanged("ModelState");
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnPropertyChanged(e);
|
||||
if (e.PropertyName == "Data")
|
||||
if (e.PropertyName.StartsWith("Data"))
|
||||
{
|
||||
SyncData();
|
||||
}
|
||||
|
|
@ -61,6 +70,7 @@ namespace BookAStar.ViewModels.EstimateAndBilling
|
|||
Data.Bill = Bill.Select(l => l.Data).ToList();
|
||||
NotifyPropertyChanged("FormattedTotal");
|
||||
NotifyPropertyChanged("Bill");
|
||||
NotifyPropertyChanged("ViewModelState");
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
|
|
@ -127,7 +137,7 @@ namespace BookAStar.ViewModels.EstimateAndBilling
|
|||
get
|
||||
{
|
||||
OnPlatform<Font> lfs = (OnPlatform<Font>)App.Current.Resources["MediumFontSize"];
|
||||
OnPlatform<Color> etc = (OnPlatform<Color>)App.Current.Resources["EmphasisTextColor"];
|
||||
Color etc = (Color) App.Current.Resources["EmphasisTextColor"];
|
||||
|
||||
return new FormattedString
|
||||
{
|
||||
|
|
@ -135,7 +145,7 @@ namespace BookAStar.ViewModels.EstimateAndBilling
|
|||
Spans = {
|
||||
new Span { Text = "Total TTC: " },
|
||||
new Span { Text = Data.Total.ToString(),
|
||||
ForegroundColor = etc.Android ,
|
||||
ForegroundColor = etc,
|
||||
FontSize = (double) lfs.Android.FontSize },
|
||||
new Span { Text = "€", FontSize = (double) lfs.Android.FontSize }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,7 @@
|
|||
using BookAStar.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using System;
|
||||
using XLabs.Forms.Mvvm;
|
||||
using System.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BookAStar.ViewModels.Validation
|
||||
{
|
||||
|
|
@ -16,7 +11,7 @@ namespace BookAStar.ViewModels.Validation
|
|||
/// </summary>
|
||||
public class EditingViewModel<DataType>: ViewModel
|
||||
{
|
||||
|
||||
[JsonIgnore]
|
||||
public Action<DataType, ModelState> CheckCommand { set; get; }
|
||||
|
||||
public DataType Data { get; set; }
|
||||
|
|
@ -44,13 +39,16 @@ namespace BookAStar.ViewModels.Validation
|
|||
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnPropertyChanged(e);
|
||||
Check();
|
||||
}
|
||||
public virtual void Check()
|
||||
{
|
||||
if (CheckCommand != null)
|
||||
{
|
||||
ViewModelState.Clear();
|
||||
CheckCommand(Data, ViewModelState);
|
||||
}
|
||||
}
|
||||
|
||||
/* NOTE : I had a dream.
|
||||
|
||||
bool existsRemotely;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue