예제 #1
0
        private async Task Refresh()
        {
            try
            {
                using (var dlg = this.Dialogs.Loading("Progress (No Cancel)"))
                {
                    var boardResult = await _boardsService.GetBoardDetails(_boardId, BuildingId);

                    var boardTestResult = await _boardsService.GetBoardTestDetails(_boardId, CertificateId);

                    if (!boardResult.Success || !boardResult.Success)
                    {
                        Dialogs.Toast(boardResult.Message);
                        return;
                    }

                    var board     = boardResult.ResultObject as Board;
                    var boardTest = boardTestResult.ResultObject as BoardTest;
                    if (board != null)
                    {
                        BasicInfoViewModel.Board = boardTest;

                        var circuitResult = await _boardsService.GetTestedCircuits(CertificateId, board.BoardId);

                        if (!circuitResult.Success)
                        {
                            Dialogs.Toast(circuitResult.Message);
                            return;
                        }

                        var circuits = new List <CircuitTest>();

                        var circuitTest = circuitResult.ResultObject as List <CircuitTest>;
                        if (circuitTest != null)
                        {
                            CircuitsViewModel.TestedCircuits.Clear();
                            CircuitsViewModel.Circuits.Clear();

                            CircuitsViewModel.TestedCircuits = circuitTest;

                            foreach (var circuit in board.Circuits)
                            {
                                if (board.BoardPhase == "3" || board.BoardPhase == "TP&N")
                                {
                                    if (circuitTest.FirstOrDefault(x => x.CircuitReference == circuit.CircuitReference)?.CircuitIs3Phase == "Y")
                                    {
                                        if (CircuitsViewModel.Circuits.Any(x => x.Circuit.CircuitReference == circuit.CircuitReference))
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            circuit.NotBelongsToThreePhase = false;
                                            circuit.ThreePhase             = circuit.CircuitReference + board.BoardCircuitPhaseNaming;
                                            CircuitsViewModel.Circuits.Add(new CircuitSelect
                                            {
                                                Circuit    = circuit,
                                                IsSelected = circuitTest.Any(x => x.CircuitId == circuit.CircuitId && x.CircuitReference == circuit.CircuitReference)
                                            });
                                            continue;
                                        }
                                    }
                                }

                                CircuitsViewModel.Circuits.Add(new CircuitSelect
                                {
                                    Circuit    = circuit,
                                    IsSelected = circuitTest.Any(x => x.CircuitId == circuit.CircuitId)
                                });
                            }

                            CircuitsViewModel.Refresh();

                            await BasicInfoViewModel.InitializeAsync(null);
                        }
                    }
                }
            }
            catch (ServiceAuthenticationException e)
            {
                var result = await TryToLogin();

                if (!result)
                {
                    await NavigationService.NavigateToAsync <LoginViewModel>();
                }
                else
                {
                    await InitializeAsync(_boardId);
                }
            }
            catch (Exception e)
            {
                await ShowErrorAlert(e.Message);
            }
        }
예제 #2
0
        public override async Task InitializeAsync(object navigationData)
        {
            MessagingCenter.Subscribe <BasicInfoPage, string>(this, MessengerCenterMessages.ChangeTitleOnCertificateTab, (details, s) =>
            {
                Title = s;
            });
            MessagingCenter.Subscribe <AssociatedBoardsPage, string>(this, MessengerCenterMessages.ChangeTitleOnCertificateTab, (details, s) =>
            {
                Title = s;
            });
            MessagingCenter.Subscribe <EditPointPage, string>(this, MessengerCenterMessages.ChangeTitleOnCertificateTab, (details, s) =>
            {
                Title = s;
            });

            var certId = navigationData as string;

            if (certId != null)
            {
                _certId = certId;
            }

            try
            {
                using (var dlg = this.Dialogs.Loading("Progress (No Cancel)"))
                {
                    var certResult = await _certificatesService.GetCertificateDetails(BuildingId, _certId);

                    if (!certResult.Success)
                    {
                        Dialogs.Toast(certResult.Message);
                        return;
                    }

                    var cert = certResult.ResultObject as EditCertificate;

                    if (cert != null)
                    {
                        await loadBuildingUsers();

                        var amendDates = await _lookupsService.GetBsAmendmentDates(false);

                        List <BsAmendmentDates> bsAmendmentDates = (List <BsAmendmentDates>)amendDates;

                        BasicInfoViewModel.Certificate        = cert.CertificateBasicInfo;
                        BasicInfoViewModel.Contractors        = Contractors;
                        BasicInfoViewModel.SelectedContractor = Contractors.FirstOrDefault(x => x.UserId == cert.CertificateBasicInfo.ConUserId);
                        //BasicInfoViewModel.RaisePropertyChanged(() => SelectedContractor);

                        BasicInfoViewModel.Supervisors        = Supervisors;
                        BasicInfoViewModel.SelectedSupervisor = Supervisors.FirstOrDefault(x => x.UserId == cert.CertificateBasicInfo.EsUserId);
                        //BasicInfoViewModel.RaisePropertyChanged(() => SelectedSupervisor);

                        BasicInfoViewModel.BsAmendmentDates        = bsAmendmentDates;
                        BasicInfoViewModel.SelectedBsAmendmentDate = bsAmendmentDates.FirstOrDefault(x => x.CertDateAmended == cert.CertificateBasicInfo.CertDateAmended);
                        //BasicInfoViewModel.RaisePropertyChanged(() => SelectedBsAmendmentDate);

                        AssociatedBoardsViewModel.AssociatedBoards.AddRange(cert.CertificateAssociatedBoards
                                                                            .BoardTests);

                        foreach (var board in cert.CertificateAssociatedBoards.BoardTests)
                        {
                            await _boardsService.GetBoardDetails(board.BoardId, BuildingId);
                        }
                    }

                    await EditPointViewModel.InitializeAsync(null);
                }
            }
            catch (ServiceAuthenticationException e)
            {
                var result = await TryToLogin();

                if (!result)
                {
                    await NavigationService.NavigateToAsync <LoginViewModel>();
                }
                else
                {
                    await InitializeAsync(navigationData);
                }
            }
            catch (Exception e)
            {
                await ShowErrorAlert(e.Message);
            }
        }