Beispiel #1
0
        private void SetFrameContent()
        {
            var item = this.PrevViewStack.Pop();

            this.FrameContent = item;
            this.NextViewStack.Push(item);
            CompleteCommand.RaiseCanExecuteChanged();
            PreviousCommand.RaiseCanExecuteChanged();
            NextCommand.RaiseCanExecuteChanged();
        }
 private void OnComplete(bool?selected)
 {
     if (selected == true)
     {
         service.CompleteTask(Task);
     }
     else if (selected == false)
     {
         service.StartTask(Task);
     }
     CompleteCommand.RaiseCanExecuteChanged();
     StartCommand.RaiseCanExecuteChanged();
 }
Beispiel #3
0
 private async System.Threading.Tasks.Task OnComplete(bool?selected)
 {
     try
     {
         if (selected == true)
         {
             await _service.ChangeTaskStatusAsync(Task, TaskStatus.TaskComplete);
         }
         else if (selected == false)
         {
             await _service.ChangeTaskStatusAsync(Task, TaskStatus.TaskNotStarted);
         }
     }
     catch (TimeoutException timeoutEx)
     {
         _eventAggregator.GetEvent <TimeoutErrorEvent>().Publish(timeoutEx);
     }
     CompleteCommand.RaiseCanExecuteChanged();
     StartCommand.RaiseCanExecuteChanged();
 }
Beispiel #4
0
        public VehicleInspectionPageViewModel(INavigationService navigationService, IEventAggregator eventAggregator)
            : base(navigationService)
        {
            try
            {
                _navigationService          = navigationService;
                this._eventAggregator       = eventAggregator;
                this.InspectionUserControls = new ObservableCollection <UserControl>();
                this.CustomerDetails        = new CustomerDetails();

                this.PrevViewStack = new Stack <UserControl>();
                // LoadDemoAppointments();

                this.CompleteCommand = new DelegateCommand(async() =>
                {
                    this.IsBusy            = true;
                    this._task.ProcessStep = ProcessStep.AcceptInspection;
                    this._task.ShouldSync  = true;
                    this._task.Status      = Pithline.FMS.BusinessLogic.Helpers.TaskStatus.AwaitDamageConfirmation;
                    await SqliteHelper.Storage.UpdateSingleRecordAsync(this._task);
                    var currentViewModel = ((BaseViewModel)this.NextViewStack.Peek().DataContext);
                    var currentModel     = currentViewModel.Model;

                    if (currentViewModel is TTyreConditionUserControlViewModel)
                    {
                        await((TTyreConditionUserControlViewModel)currentViewModel).SaveTrailerTyreConditions(this._task.VehicleInsRecId);
                    }
                    else
                    {
                        this.SaveCurrentUIDataAsync(currentModel);
                    }
                    _navigationService.Navigate("Main", null);

                    await VIServiceHelper.Instance.UpdateTaskStatusAsync();
                    this.IsBusy = false;
                }, () =>
                {
                    var vm = ((BaseViewModel)this.NextViewStack.Peek().DataContext);
                    if (vm is InspectionProofUserControlViewModel)
                    {
                        return((this.NextViewStack.Count == 1) && (((InspectionProofUserControlViewModel)vm).CustSignature != null) && (((InspectionProofUserControlViewModel)vm).PithlineRepSignature != null));
                    }
                    else if (vm is CPOIUserControlViewModel)
                    {
                        return((this.NextViewStack.Count == 1) && (((CPOIUserControlViewModel)vm).CustSignature != null) && (((CPOIUserControlViewModel)vm).PithlineRepSignature != null));
                    }
                    else
                    {
                        return(this.NextViewStack.Count == 1);
                    }
                });

                this._eventAggregator.GetEvent <SignChangedEvent>().Subscribe(p =>
                {
                    CompleteCommand.RaiseCanExecuteChanged();
                });

                this._eventAggregator.GetEvent <ErrorsRaisedEvent>().Subscribe((errors) =>
                {
                    Errors = errors;
                    OnPropertyChanged("Errors");
                    ShowValidationSummary = true;
                    OnPropertyChanged("ShowValidationSummary");
                }, ThreadOption.UIThread);

                this.NextCommand = new DelegateCommand(async() =>
                {
                    //this.IsCommandBarOpen = false;
                    //this.IsFlyoutOpen = true;
                    ShowValidationSummary = false;
                    var currentViewModel  = (BaseViewModel)this.NextViewStack.Peek().DataContext;
                    var currentModel      = currentViewModel.Model as BaseModel;

                    if (currentModel.ValidateModel() && await currentModel.VehicleDetailsImagesValidate())
                    {
                        this.PrevViewStack.Push(this.NextViewStack.Pop());
                        if (currentViewModel is TTyreConditionUserControlViewModel)
                        {
                            await((TTyreConditionUserControlViewModel)currentViewModel).SaveTrailerTyreConditions(this._task.VehicleInsRecId);
                        }
                        else
                        {
                            this.SaveCurrentUIDataAsync(currentModel);
                        }

                        this.FrameContent = this.NextViewStack.Peek();
                        CompleteCommand.RaiseCanExecuteChanged();
                        NextCommand.RaiseCanExecuteChanged();
                        PreviousCommand.RaiseCanExecuteChanged();
                        if (this.NextViewStack.FirstOrDefault() != null)
                        {
                            BaseViewModel nextViewModel = this.NextViewStack.FirstOrDefault().DataContext as BaseViewModel;
                            await nextViewModel.LoadModelFromDbAsync(this._task.VehicleInsRecId);
                        }
                    }
                    else
                    {
                        Errors = currentModel.Errors;
                        OnPropertyChanged("Errors");
                        ShowValidationSummary = true;
                    }
                }, () =>
                {
                    return(this.NextViewStack.Count > 1);
                });


                this.PreviousCommand = new DelegateCommand(async() =>
                {
                    this.IsCommandBarOpen = false;
                    ShowValidationSummary = false;
                    var currentViewModel  = ((BaseViewModel)this.NextViewStack.Peek().DataContext);
                    var currentModel      = currentViewModel.Model as BaseModel;

                    if (currentModel is PInspectionProof)
                    {
                        ((InspectionProofUserControlViewModel)this.NextViewStack.Peek().DataContext).CustSignature        = null;
                        ((InspectionProofUserControlViewModel)this.NextViewStack.Peek().DataContext).PithlineRepSignature = null;
                        SetFrameContent();
                    }
                    else if (currentModel is CPOI)
                    {
                        ((CPOIUserControlViewModel)this.NextViewStack.Peek().DataContext).CustSignature        = null;
                        ((CPOIUserControlViewModel)this.NextViewStack.Peek().DataContext).PithlineRepSignature = null;
                        SetFrameContent();
                    }

                    else
                    {
                        if (currentModel.ValidateModel())
                        {
                            SetFrameContent();


                            if (currentViewModel is TTyreConditionUserControlViewModel)
                            {
                                await((TTyreConditionUserControlViewModel)currentViewModel).SaveTrailerTyreConditions(this._task.VehicleInsRecId);
                            }
                            else
                            {
                                this.SaveCurrentUIDataAsync(currentModel);
                            }

                            if (this.PrevViewStack.FirstOrDefault() != null)
                            {
                                BaseViewModel nextViewModel = this.PrevViewStack.FirstOrDefault().DataContext as BaseViewModel;
                                await nextViewModel.LoadModelFromDbAsync(this._task.VehicleInsRecId);
                            }
                        }
                        else
                        {
                            Errors = currentModel.Errors;
                            OnPropertyChanged("Errors");
                            ShowValidationSummary = true;
                        }
                    }
                }, () =>
                {
                    return(this.PrevViewStack.Count > 0);
                });
            }
            catch (Exception)
            {
                throw;
            }
        }
        public TechnicalInspectionPageViewModel(INavigationService navigationService, IEventAggregator eventAggregator)
            : base(navigationService)
        {
            try
            {
                _navigationService          = navigationService;
                this._eventAggregator       = eventAggregator;
                this.InspectionUserControls = new ObservableCollection <UserControl>();
                this.CustomerDetails        = new CustomerDetails();
                this.MaintenanceRepairList  = new ObservableCollection <MaintenanceRepair>();
                this.Model = new TIData();



                this.CompleteCommand = new DelegateCommand(async() =>
                {
                    try
                    {
                        this.IsBusy = true;
                        AppSettings.Instance.IsSynchronizing = 1;
                        this._task.Status = Pithline.FMS.BusinessLogic.Helpers.TaskStatus.Completed;
                        await SqliteHelper.Storage.UpdateSingleRecordAsync(this._task);
                        var model             = ((TIData)this.Model);
                        model.ShouldSave      = true;
                        model.VehicleInsRecID = _task.CaseServiceRecID;
                        var tiDataTable       = await SqliteHelper.Storage.LoadTableAsync <TIData>();
                        if (tiDataTable.Any(x => x.VehicleInsRecID == model.VehicleInsRecID))
                        {
                            await SqliteHelper.Storage.UpdateSingleRecordAsync <TIData>(model);
                        }
                        else
                        {
                            await SqliteHelper.Storage.InsertSingleRecordAsync <TIData>(model);
                        }
                        TIServiceHelper.Instance.Synchronize();
                        // this.SaveCurrentUIDataAsync(currentModel);
                        _navigationService.Navigate("Main", null);

                        //await TIServiceHelper.Instance.UpdateTaskStatusAsync();
                        this.IsBusy = false;
                        _eventAggregator.GetEvent <TITaskFetchedEvent>().Publish(this._task);
                    }
                    catch (Exception ex)
                    {
                        this.IsBusy = false;
                        AppSettings.Instance.IsSynchronizing = 0;
                        AppSettings.Instance.ErrorMessage    = ex.Message;
                    }
                });

                this._eventAggregator.GetEvent <SignChangedEvent>().Subscribe(p =>
                {
                    CompleteCommand.RaiseCanExecuteChanged();
                });

                this._eventAggregator.GetEvent <ErrorsRaisedEvent>().Subscribe((errors) =>
                {
                    Errors = errors;
                    OnPropertyChanged("Errors");
                    ShowValidationSummary = true;
                    OnPropertyChanged("ShowValidationSummary");
                }, ThreadOption.UIThread);
            }
            catch (Exception)
            {
                throw;
            }
        }