2 pièce(s) jointe(s)
View ViewModel et tables multiples
Bonjour;
Voilà plusieurs jours que j'écris des messages afin de disposer d'aide mais que mes topics visent plusieurs sujets qui se rejoignent et sont un peu flous.
Je me permets donc de créer un nouveau topic plus global avec des informations moins floues et des détails.
Je cherche à créer un formulaire pour créer des commandes; celle-ci se compose de lignes de commandes.
Chaque ligne peut être associée à un numéro d'affaire qui peut être différent pour chaque ligne de la commande(table Affaires).
Ma base de données ressemble à ceci :
Pièce jointe 150158
Je cherche à créer ce genre de View :
Pièce jointe 150159
Pour ce qui est de mon CommandeFournisseurViewModel il est fait de cette manière :
Code:
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
| namespace ViewModel
{
public class CommandeFournisseurViewModel : BaseViewModel<CommandeFournisseur>, INotifyPropertyChanged
{
public CommandeFournisseurViewModel(CommandeFournisseur CommandeFournisseur) : base(CommandeFournisseur)
{
Titre = "CommandeFournisseur";
}
public CommandeFournisseur CommandeFournisseur
{
get { return ObjectEntity as CommandeFournisseur; }
}
public EntityCollection<CommandeFournisseurLigne> CommandeFournisseurLignes
{
get { return ObjectEntity.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 ObservableCollection<CommandeFournisseurLigne> _test = null;
public ObservableCollection<CommandeFournisseurLigne> test
{
get {
if (_test == null)
{
_test = new ObservableCollection<CommandeFournisseurLigne>(CommandeFournisseur.CommandeFournisseurLignes);
}
return _test;
}
set { _test = value; }
}
private ICommand _DeleteLine = null;
public ICommand DeleteLine
{
get
{
if (_DeleteLine == null)
_DeleteLine = new DelegateCommand<CommandeFournisseurLigne>((CommandeFournisseurLigne Parametre) => ExecuteSupprimerLigne(Parametre));
return _DeleteLine;
}
}
private void ExecuteSupprimerLigne(CommandeFournisseurLigne Parametre)
{
CommandeFournisseurLignes.Remove(Parametre);
}
} |
Ce qui me permet d'atteindre EntityCollection<CommandeFournisseurLigne> CommandeFournisseurLignes.
Cela me permet d'obtenir les lignes de la commande ainsi que le numéro d'affaire de chaque ligne via :
<ig:TextColumn Key="Affaire.Numero"/>
Pour ce qui est du binding de ma view il est fait de cette manière :
Code:
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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
<UserControl x:Class="WpfERP.View.CommandeFournisseurView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:View="clr-namespace:WpfERP.View;assembly="
xmlns:ViewModel="clr-namespace:ViewModel;assembly=ViewModel"
mc:Ignorable="d"
d:DesignHeight="800" d:DesignWidth="1000"
xmlns:ig="http://schemas.infragistics.com/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
MinHeight="400" MinWidth="800"
MaxHeight="800" MaxWidth="1000">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="420"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Grid.Column="0" Grid.Row="0" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Text="N° de Cde" />
<TextBox Grid.Column="1" Grid.Row="0" Text="{Binding CommandeFournisseur.NumeroCommande}" />
<TextBlock Grid.Column="0" Grid.Row="1" Text="Demandeur" />
<TextBox Grid.Column="1" Grid.Row="1" Text="{Binding CommandeFournisseur.Personne.Nom}" />
<TextBlock Grid.Column="0" Grid.Row="2" Text="Livraison" />
<TextBox Grid.Column="1" Grid.Row="2" Text="{Binding CommandeFournisseur.Etablissement.Nom}" />
<CheckBox Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="2" IsChecked="{Binding CommandeFournisseur.RegleParDemandeur}" Content="Réglée par le Demandeur"/>
<Grid Grid.Column="1" Grid.Row="4" HorizontalAlignment="Right" Margin="70 0 0 0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Monnaie" HorizontalAlignment="Left"/>
<ComboBox Grid.Column="1"
ItemsSource="{Binding ListeDevise}"
SelectedValue="{Binding CommandeFournisseur.Devise.ID}"
SelectedValuePath="ID" HorizontalAlignment="Right" Width="150"
>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Background="Transparent">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} - {1}">
<Binding Path="Symbole" />
<Binding Path="Libelle"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
</Grid>
<ig:XamGrid Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" x:Name="dataGrid"
ItemsSource="{Binding CommandeFournisseurLignes}"
AutoGenerateColumns="false"
DeleteKeyAction="DeleteRowOfActiveCell">
<ig:XamGrid.Columns>
<ig:TextColumn Key="Affaire.ID"/>
<ig:TextColumn Key="Description"/>
<ig:TextColumn Key="PrixUnitaire"/>
<ig:TextColumn Key="Quantite"/>
<ig:TextColumn Key="Total_HT"/>
<ig:TemplateColumn HeaderText="Supprimer" Key="CommandeFournisseur" HorizontalContentAlignment="Center">
<ig:TemplateColumn.ItemTemplate>
<DataTemplate>
<Button Template="{StaticResource commandsItemTemplate}"/>
</DataTemplate>
</ig:TemplateColumn.ItemTemplate>
</ig:TemplateColumn>
</ig:XamGrid.Columns>
<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>
<!--Edition de ligne via double click-->
<ig:XamGrid.EditingSettings>
<ig:EditingSettings AllowEditing="Row" IsMouseActionEditingEnabled="DoubleClick"
IsEnterKeyEditingEnabled="True" IsF2EditingEnabled="True"
IsOnCellActiveEditingEnabled="False" />
</ig:XamGrid.EditingSettings>
<!--Ajout de ligne via double click-->
<ig:XamGrid.AddNewRowSettings>
<ig:AddNewRowSettings AllowAddNewRow="Top"
IsEnterKeyEditingEnabled="True"
IsF2EditingEnabled="False"
IsMouseActionEditingEnabled="DoubleClick"
IsOnCellActiveEditingEnabled="True"/>
</ig:XamGrid.AddNewRowSettings>
</ig:XamGrid>
<Grid Grid.Column="1" Grid.Row="0" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.ColumnSpan="4" Grid.Row="0" Text="Informations Fournisseur" TextAlignment="Center" Margin="0 5"/>
<Label Grid.Column="0" Grid.Row="1">Nom :</Label>
<!--<TextBlock Grid.Column="0" Grid.Row="1" Text="Nom" />-->
<TextBox Grid.Column="1" Grid.Row="1" Text="123456" />
<ComboBox Grid.Column="1" Grid.Row="1"
ItemsSource="{Binding ListeFournisseur}"
SelectedValue="{Binding CommandeFournisseur.IDFournisseur}"
DisplayMemberPath="Nom"
SelectedValuePath="ID"
/>
<Label Grid.Row="1" Grid.Column="2">Autre Fournisseur :</Label>
<!--<TextBlock Grid.Column="2" Grid.Row="1" Text="Autre Fournisseur" />-->
<TextBox Grid.Column="3" Grid.Row="1" Text="" />
<Label Grid.Column="0" Grid.Row="2">N° de Devis</Label>
<!--<TextBlock Grid.Column="0" Grid.Row="2" Text="N° de Devis" />-->
<TextBox Grid.Column="1" Grid.Row="2" Text="{Binding CommandeFournisseur.NumeroDevis}" />
<Label Grid.Column="2" Grid.Row="2">Contact : </Label>
<!--<TextBlock Grid.Column="2" Grid.Row="2" Text="Contact" />-->
<TextBox Grid.Column="3" Grid.Row="2" Text="" />
<Label Grid.Column="0" Grid.Row="3">Téléphone : </Label>
<!--<TextBlock Grid.Column="0" Grid.Row="3" Text="Téléphone" />-->
<TextBox Grid.Column="1" Grid.Row="3" Text="" />
<Label Grid.Column="2" Grid.Row="3">Fax :</Label>
<!--<TextBlock Grid.Column="2" Grid.Row="3" Text="Fax" />-->
<TextBox Grid.Column="3" Grid.Row="3" Text="" />
<Label Grid.Column="0" Grid.Row="4">Délai :</Label>
<!--<TextBlock Grid.Column="0" Grid.Row="4" Text="Délai" />-->
<TextBox Grid.Column="1" Grid.Row="4" Text="" />
<Label Grid.Column="2" Grid.Row="4">Règlement :</Label>
<!--<TextBlock Grid.Column="2" Grid.Row="4" Text="Règlement" />-->
<TextBox Grid.Column="3" Grid.Row="4" Text="" />
<Label Grid.Column="0" Grid.Row="5">Commentaire :</Label>
<!--<TextBlock Grid.Column="0" Grid.Row="5" Text="Commentaire" />-->
<TextBox Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="5" Text="" />
</Grid>
</Grid>
</UserControl> |
Mes problèmes sont les suivants :
1) lorsque je supprime une ligne commande seule la valeur de la clé étrangère de la ligne commande et passé à NULL; ce que je ne tolère pas dans ma BDD car contrainte non NULL.
De plus il ne s'agit pas que de la suppression de la liaison mais belle est bien de la ligne de commande, celle-ci doit donc être supprimée de la table LigneCommande et non pas modifier la clé étrangère.
2) Lors de la modification du numéro d'affaire, la modif se répercute dans la table Affaires et change le numéro d'affaire dans la table alors que mon objectif est de modifier la liaison entre la commande ligne et le numéro d'affaire afin d'attribuer la commande ligne à une autre affaire . (Cas inverse du précédent)
Update de la table Affaire au lieu de la colonne id affaire de CommandeFournisseurLigne.
Edit :
J'ai un peu avancer, j'ai remplacé le binding suivant "Affaire.ID" à "IDAffaire" qui appartient à l'objet commandeLigne. Le seul hic c'est que cette ID ne veut rien dire pour un utilisateur lambda...
j'aimerai afficher quelque chose de plus cohérent du genre le libélle et non pas un chiffre entre 1 et 1000.
3) Comment maintenir ma vue à jour ?
4) J'aimerais remplacer le texte de la textbox du tableau (numéro) pas une combo-box permettant de choisir à quel numéro d'affaire attribuer la ligne.
La textbox pourrait être préchargée par les infos retrouvées dans la table Affaires.
Je ne sais donc pas comment résoudre ces problèmes qui ne me permettent pas de réaliser le fonctionnement que j'ai prévu.
Merci pour toute votre aide déjà apportée et celle que vous pourriez m'apporter en plus.