Beispiel #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);
            }
        }
        public async Task CheckDoesEveryBoardHasAssociatedCircuit()
        {
            try
            {
                var listOfBoards = "";
                DoesEveryBoardHasAssociatedCircuit = true;

                var testedBoardsResult = await _boardsService.GetTestedBoards(CertificateId);

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

                var boards = testedBoardsResult.ResultObject as List <BoardTest>;
                if (boards != null && boards.Any())
                {
                    foreach (var board in boards)
                    {
                        var circuitResult = await _boardsService.GetTestedCircuits(CertificateId, board.BoardId);

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

                        var circuitTest = circuitResult.ResultObject as List <CircuitTest>;
                        if (circuitTest != null)
                        {
                            if (circuitTest.Any())
                            {
                                continue;
                            }

                            DoesEveryBoardHasAssociatedCircuit = false;
                            listOfBoards += board.BoardIdentity + ", ";
                        }
                    }
                    if (!string.IsNullOrEmpty(listOfBoards))
                    {
                        listOfBoards += ".";
                        listOfBoards  = listOfBoards.Replace(", .", ".");

                        ListOfBoardsWithoutAssociatedCircuit = listOfBoards;
                        ErrorMessage = "Following boards: " + ListOfBoardsWithoutAssociatedCircuit +
                                       " Has no circuit selected, please select a board and then associate a circuit!";

                        ShowError();
                    }

                    MessagingCenter.Send(this,
                                         DoesEveryBoardHasAssociatedCircuit
                            ? MessengerCenterMessages.ShowBackOnCertificateDetails
                            : MessengerCenterMessages.HideBackOnCertificateDetails);
                }
            }
            catch (Exception e)
            {
                await ShowErrorAlert(e.Message);
            }
        }
Beispiel #3
0
        private async Task GetCircuitsForCurrentBoard()
        {
            try
            {
                _inCode = true;

                if (Boards != null && Boards.Any() && CurrentBoardPosition == -1)
                {
                    CurrentBoardPosition = 0;
                }

                if (Boards != null)
                {
                    SelectedBoard = Boards[CurrentBoardPosition];
                }
                var result = await _boardsService.GetTestedCircuits(CertificateId, SelectedBoard.BoardId);

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

                var circuitTest = result.ResultObject as List <CircuitTest>;
                if (circuitTest == null)
                {
                    return;
                }

                CurrentCircuitPosition = 0;
                Circuits.Clear();

                var circuits = new List <CircuitTest>();

                if (SelectedBoard.BoardPhase == "3" || SelectedBoard.BoardPhase == "TP&N")
                {
                    var numberToSkip       = 0;
                    var numbers            = circuitTest.Select(x => x.CircuitReference).Distinct();
                    var threePhaseCircutes = new List <int>();

                    foreach (var number in numbers)
                    {
                        if (circuitTest.Any(x => x.CircuitReference == number && x.CircuitIs3Phase == "Y"))
                        {
                            threePhaseCircutes.Add(number);
                        }
                    }

                    if (!threePhaseCircutes.Any())
                    {
                        circuits.AddRange(circuitTest);
                    }
                    else
                    {
                        foreach (var circuit in circuitTest)
                        {
                            if (circuit.CircuitReference == numberToSkip)
                            {
                                continue;
                            }

                            if (threePhaseCircutes.Contains(circuit.CircuitReference))
                            {
                                if (circuit.CircuitIs3Phase == "Y")
                                {
                                    circuit.NotBelongsToThreePhase = false;
                                    circuit.ThreePhase             = circuit.CircuitReference + SelectedBoard.BoardCircuitPhaseNaming;
                                    circuits.Add(circuit);
                                    numberToSkip = circuit.CircuitReference;
                                }
                                continue;
                            }
                            circuit.NotBelongsToThreePhase = true;
                            circuits.Add(circuit);
                        }
                    }
                }
                else
                {
                    circuits.AddRange(circuitTest);
                }

                Circuits = new ObservableCollectionFast <CircuitTest>(circuits.OrderBy(x => x.ThreePhaseRepresentation));

                //Circuits.AddRange(new List<CircuitTest>(circuitTest.OrderBy(x => x.CircuitIdentity)));

                GetPointsForCurrentCircuit();

                _inCode = false;
            }
            catch (ServiceAuthenticationException e)
            {
                var result = await TryToLogin();

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