Exemplo n.º 1
0
        public SessionVM(StartStopSessionViewModel vm, dev1_session data)
        {
            if (data != null)
            {
                

              
                this.dev1_sessionid.SetValue(data.dev1_sessionId);
                this.dev1_description.SetValue(data.dev1_Description);
                this.dev1_duration.SetValue(data.dev1_Duration);
                this.dev1_endtime.SetValue(data.dev1_EndTime);
                this.dev1_starttime.SetValue(data.dev1_StartTime);
                // Calculate the time elements
                GetTime(dev1_starttime, StartTimeTime);
                GetTime(dev1_endtime, EndTimeTime);

               

                // Set activity
                if (data.dev1_LetterId != null)
                {
                   

                    this.Activity.SetValue(data.dev1_LetterId);
                }
                else if (data.dev1_TaskId != null)
                {
                    this.Activity.SetValue(data.dev1_TaskId);
                    
                }
                 // TODO: Add more activity types
            }

            // Add events to calculate duration
            dev1_endtime.Subscribe(delegate(DateTime value) { OnStartEndDateChanged(); });

            dev1_starttime.Subscribe(delegate(DateTime value) { OnStartEndDateChanged(); });

            StartTimeTime.Subscribe(delegate(string value) { OnStartEndDateChanged(); });
            EndTimeTime.Subscribe(delegate(string value) { OnStartEndDateChanged(); });
            dev1_duration.Subscribe(delegate(int? value) { OnDurationChanged(); });
            AddValidation();
        }
Exemplo n.º 2
0
        public SessionVM(StartStopSessionViewModel vm, dev1_session data)
        {
            if (data != null)
            {
                this.dev1_sessionid.SetValue(data.dev1_sessionId);
                this.dev1_description.SetValue(data.dev1_Description);
                this.dev1_duration.SetValue(data.dev1_Duration);
                this.dev1_endtime.SetValue(data.dev1_EndTime);
                this.dev1_starttime.SetValue(data.dev1_StartTime);
                // Calculate the time elements
                GetTime(dev1_starttime, StartTimeTime);
                GetTime(dev1_endtime, EndTimeTime);



                // Set activity
                if (data.dev1_LetterId != null)
                {
                    this.Activity.SetValue(data.dev1_LetterId);
                }
                else if (data.dev1_TaskId != null)
                {
                    this.Activity.SetValue(data.dev1_TaskId);
                }
                // TODO: Add more activity types
            }

            // Add events to calculate duration
            dev1_endtime.Subscribe(delegate(DateTime value) { OnStartEndDateChanged(); });

            dev1_starttime.Subscribe(delegate(DateTime value) { OnStartEndDateChanged(); });

            StartTimeTime.Subscribe(delegate(string value) { OnStartEndDateChanged(); });
            EndTimeTime.Subscribe(delegate(string value) { OnStartEndDateChanged(); });
            dev1_duration.Subscribe(delegate(int?value) { OnDurationChanged(); });
            AddValidation();
        }
        public StartStopSessionViewModel(Guid activityToStartStop, Guid sessionToStartStop)
        {
            // Create start session
            dev1_session newSession = new dev1_session();

            newSession.dev1_StartTime = DateTime.Now;
            StartSession = (Observable <SessionVM>)ValidatedObservableFactory.ValidatedObservable(new SessionVM(this, newSession));

            // Load the Sessions
            dev1_session session   = (dev1_session)OrganizationServiceProxy.Retrieve(dev1_session.EntityLogicalName, "{FD722AC2-B234-E211-A471-000C299FFE7D}", new string[] { "AllColumns" });
            SessionVM    sessionVM = new SessionVM(this, session);

            StopSession = (Observable <SessionVM>)ValidatedObservableFactory.ValidatedObservable(sessionVM);

            DependentObservableOptions <bool> isFormValidDependantProperty = new DependentObservableOptions <bool>();

            isFormValidDependantProperty.Model = this;

            isFormValidDependantProperty.GetValueFunction = new Func <bool>(delegate
            {
                StartStopSessionViewModel vm = (StartStopSessionViewModel)isFormValidDependantProperty.Model;

                if (vm.StartNewSession.GetValue())
                {
                    return(ValidationRules.AreValid(
                               new object[] { ((StartStopSessionViewModel)isFormValidDependantProperty.Model).StopSession,
                                              ((StartStopSessionViewModel)isFormValidDependantProperty.Model).StartSession }));
                }
                else
                {
                    return(ValidationRules.AreValid(
                               new object[] { ((StartStopSessionViewModel)isFormValidDependantProperty.Model).StopSession }));
                }
            });
            CanSave = Knockout.DependentObservable <bool>(isFormValidDependantProperty);
        }
Exemplo n.º 4
0
        public static void Init()
        {
            StartStopSessionViewModel vm = new StartStopSessionViewModel(null, null);
            RegisterViewModel(vm);

        }