Bonjour,
J'ai réalisé un tableau avec les lignes de commande que je suis en train de visualiser.
Ce qui donne ceci :
Mon problème et que je peux mettre à jour chaque ligne.
Lorsque je modifie la quantité ou le prix unitaire je ne sais pas comment mettre à jour le total_ht.
Mon tableau est fait de cette façon :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 <ig:XamGrid Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" x:Name="dataGridTest" ItemsSource="{Binding other , UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="false"> <ig:XamGrid.Columns> <ig:TemplateColumn Key="CommandeFournisseurLigne" HeaderText="Numéro d'affaire"> <ig:TemplateColumn.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding CommandeFournisseurLigne.Affaire.Numero, UpdateSourceTrigger=PropertyChanged}" /> </DataTemplate> </ig:TemplateColumn.ItemTemplate> <ig:TemplateColumn.EditorTemplate> <DataTemplate> <ComboBox Width="50" ItemsSource="{Binding Source={x:Static ViewModel:CommandeFournisseurViewModel.ListeAffaire}}" SelectedValue="{Binding CommandeFournisseurLigne.IDAffaire, UpdateSourceTrigger=PropertyChanged}" DisplayMemberPath="Numero" SelectedValuePath="ID" /> </DataTemplate> </ig:TemplateColumn.EditorTemplate> </ig:TemplateColumn> <!--<ig:TextColumn Key="CommandeFournisseurLigne.Affaire.Numero" IsReadOnly="True"/>--> <ig:TextColumn Key="CommandeFournisseurLigne.Description" /> <ig:TextColumn Key="CommandeFournisseurLigne.PrixUnitaire"/> <ig:TextColumn Key="CommandeFournisseurLigne.Quantite"/> <ig:TextColumn Key="CommandeFournisseurLigne.Total_HT" IsReadOnly="True"/> <ig:TemplateColumn Key="CommandeFournisseurLigne.ID" HeaderText="Supprimer" HorizontalContentAlignment="Center" IsReadOnly="True"> <ig:TemplateColumn.ItemTemplate> <DataTemplate> <Button Height="15" Style="{StaticResource RemoveButtonStyle}" CommandParameter="{Binding}" Command="{Binding DataContext.DeleteLine, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ig:XamGrid}}}"/> </DataTemplate> </ig:TemplateColumn.ItemTemplate> </ig:TemplateColumn> </ig:XamGrid.Columns> <ig:XamGrid.AddNewRowSettings> <ig:AddNewRowSettings AllowAddNewRow="Bottom" IsEnterKeyEditingEnabled="True" IsF2EditingEnabled="False" IsMouseActionEditingEnabled="DoubleClick" IsOnCellActiveEditingEnabled="True"/> </ig:XamGrid.AddNewRowSettings> <!--Edition de ligne via double click--> <ig:XamGrid.EditingSettings> <ig:EditingSettings AllowEditing="Row" IsMouseActionEditingEnabled="DoubleClick" IsEnterKeyEditingEnabled="True" IsF2EditingEnabled="True" IsOnCellActiveEditingEnabled="False" /> </ig:XamGrid.EditingSettings> <ig:XamGrid.SelectionSettings> <ig:SelectionSettings CellClickAction="SelectRow" CellSelection="Single" RowSelection="Single"></ig:SelectionSettings> </ig:XamGrid.SelectionSettings> <ig:XamGrid.RowSelectorSettings> <ig:RowSelectorSettings Visibility="Hidden"/> </ig:XamGrid.RowSelectorSettings> </ig:XamGrid>
Mon ViewModel :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121 public class CommandeFournisseurViewModel : BaseViewModel<CommandeFournisseur> { public CommandeFournisseurViewModel(CommandeFournisseur CommandeFournisseur) : base(CommandeFournisseur) { Titre = "CommandeFournisseur"; } public CommandeFournisseur CommandeFournisseur { get { return ObjectEntity as CommandeFournisseur; } } public EntityCollection<CommandeFournisseurLigne> CommandeFournisseurLignes { get { return CommandeFournisseur.CommandeFournisseurLignes as EntityCollection<CommandeFournisseurLigne>; } } private static ObservableCollection<Devise> _ListeDevise = null; public ObservableCollection<Devise> ListeDevise { get { if (_ListeDevise == null) { _ListeDevise = new ObservableCollection<Devise>(DataAccess.EntitiesContext.Context.Devises); } return _ListeDevise; } } private static ObservableCollection<Fournisseur> _ListeFournisseur = null; public ObservableCollection<Fournisseur> ListeFournisseur { get { if (_ListeFournisseur == null) { _ListeFournisseur = new ObservableCollection<Fournisseur>(DataAccess.EntitiesContext.Context.Fournisseurs.OrderBy(F => F.Nom)); } return _ListeFournisseur; } } private static ObservableCollection<Etablissement> _ListeEtablissement = null; public ObservableCollection<Etablissement> ListeEtablissement { get { if (_ListeEtablissement == null) { _ListeEtablissement = new ObservableCollection<Etablissement>(DataAccess.EntitiesContext.Context.Etablissements.OrderBy(F => F.Nom)); } return _ListeEtablissement; } } private ObservableCollection<CommandeFournisseurLigneViewModel> _other = null; public ObservableCollection<CommandeFournisseurLigneViewModel> other { get { if (_other == null) { _other = new ObservableCollection<CommandeFournisseurLigneViewModel>( (from CFL in DataAccess.EntitiesContext.Context.CommandeFournisseurLignes from P in DataAccess.EntitiesContext.Context.Personnes where CFL.CommandeFournisseur.IDPersonneDemandeur == P.ID && CFL.CommandeFournisseur.ID == this.CommandeFournisseur.ID && P.IDAffectationSociete == DataAccess.EntitiesContext.Context.IDAffectationSocieteCourant && (CFL.CommandeFournisseur.DateCommande > DateTimeOutil.PremierJanvier) select CFL).ToList().Select(CFL => new CommandeFournisseurLigneViewModel(CFL))); } return _other; } set { _other = value; } } private static ObservableCollection<Affaire> _ListeAffaire = null; public static ObservableCollection<Affaire> ListeAffaire { get { if (_ListeAffaire == null) { _ListeAffaire = new ObservableCollection<Affaire>(DataAccess.EntitiesContext.Context.Affaires.OrderBy(A => A.Numero)); } return _ListeAffaire; } } public override bool CanSaveCancelCloseChange() { return true; }
Et le ViewModel de chaque ligne est le suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 public class CommandeFournisseurLigneViewModel : BaseViewModel<CommandeFournisseurLigne> { public CommandeFournisseurLigneViewModel(CommandeFournisseurLigne CommandeFournisseurLigne) : base(CommandeFournisseurLigne) { Titre = "CommandeFournisseurLigne"; } public CommandeFournisseurLigneViewModel() : base(new CommandeFournisseurLigne()) { Titre = "CommandeFournisseurLigne"; MessageBox.Show(this.ObjectEntity.ToString()); } public CommandeFournisseurLigne CommandeFournisseurLigne { get { return ObjectEntity as CommandeFournisseurLigne; } set { ObjectEntity = value; } } public CommandeFournisseur CommandeFournisseur { get { return CommandeFournisseurLigne.CommandeFournisseur as CommandeFournisseur; } } #region Command private ICommand _AfficherDetailCommand = null; public ICommand AfficherDetailCommand { get { if (_AfficherDetailCommand == null) _AfficherDetailCommand = new Framework.Windows.DelegateCommand(() => ExecuteAfficherDetail()); return _AfficherDetailCommand; } } private void ExecuteAfficherDetail() { if (this.Template == null) { this.Template = Global.GetDataTemplateFromRessource("CommandeFournisseurDataTemplate"); //(WpfERP.Outils.StyleController.FindResource("CommandeFournisseurDataTemplate") as DataTemplate); } Global.AfficherPopUP(new CommandeFournisseurViewModel(this.CommandeFournisseur), true); }
Et le total est récupéré de cette façon :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 public partial class CommandeFournisseurLigne : EntityObject { private double? _Total_HT = null; public double? Total_HT { get { if (!_Total_HT.HasValue) { _Total_HT = PrixUnitaire * Quantite; } return _Total_HT.Value; } }
Je ne sais pas comment utiliser PropertyChanged dans ce cas...
Partager