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
   | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using TP5.Events;
using TP5.Utilities;
using Contrat;
 
namespace TP5.VueEditWindow
{
    public class EditionViewModel : DependencyObject
    {
        /**Déclaration des propriétés du Model et de la vue**/
 
        //Permet de référencer le Model
        public EditionModel Model { get; set; }
 
        //Permet de référencer la View
        public Edition View { get; set; }
 
        //Méthode permettant d'initialiser la vue Edition (Model, Vue et DataContext)
        public EditionViewModel()
        {
            BtnCancelCommand = new Command(new Action<object>(ExecuteBtnCancelCommand));
            BtnOkCommand = new Command(new Action<object>(ExecuteBtnOkCommand));
 
            Model = new EditionModel();
            View = new Edition();
 
            View.DataContext = this;
        }
 
 
 
 
        // Méthode d'initialisation du binding
        public void Start()
        {
            View.Show();
        }
 
        #region BtnOkCommand
 
        private void ExecuteBtnOkCommand(object obj)
        {
            Model.unePersonne.nom = Model.nom;
            Model.unePersonne.prenom = Model.prenom;
            Model.unePersonne.age = Model.age;
            Model.unePersonne.sexe = Model.sexe;
 
            if (Model.modeAjout)
            {
                TP5.Controllers.BusinessController.do_addPersonne(Model.unePersonne);
            }
            else
            {
                TP5.Controllers.BusinessController.do_editPersonne(Model.unePersonne);
            }
 
            View.Close();
        }
 
        public ICommand BtnOkCommand
        {
            get { return (ICommand)GetValue(BtnOkCommandProperty); }
            set { SetValue(BtnOkCommandProperty, value); }
        }
 
        // Using a DependencyProperty as the backing store for OpenDialogCommand.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty BtnOkCommandProperty =
            DependencyProperty.Register("BtnOkCommand", typeof(ICommand), typeof(EditionViewModel), new UIPropertyMetadata(null));
 
        #endregion
 
 
        #region BtnCancelCommand
 
        private void ExecuteBtnCancelCommand(object obj)
        {
            View.Close();
        }
 
        public ICommand BtnCancelCommand
        {
            get { return (ICommand)GetValue(BtnCancelCommandProperty); }
            set { SetValue(BtnCancelCommandProperty, value); }
        }
 
        // Using a DependencyProperty as the backing store for OpenDialogCommand.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty BtnCancelCommandProperty =
            DependencyProperty.Register("BtnCancelCommand", typeof(ICommand), typeof(EditionViewModel), new UIPropertyMetadata(null));
 
        #endregion
 
 
    }
} | 
Partager