Exemplo n.º 1
0
        public bool ExecuteUnitChange()
        {
            if (_selectedChangeReason == null)
            {
                MessageBox.Show("Favor selecionar o motivo de saída de serviço da AM.", "Atenção!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else if (string.IsNullOrEmpty(_selectedTargetUnitId))
            {
                MessageBox.Show("Favor selecionar a AM que entrará em serviço.", "Atenção!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                try
                {
                    TargetUnitForceMap = new UnitForceMapModel()
                    {
                        UnitId = _selectedTargetUnitId
                    };

                    return(UnitForceMapBusiness.ExchangeUnit(_currentUnitForceMap, TargetUnitForceMap, _selectedChangeReason));
                }
                catch (ArgumentException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (Exception)
                {
                    MessageBox.Show("Não foi possível substituir a AM.", "Atenção!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public void GetUnitList()
        {
            try
            {
                string returnMessage;
                UnitList = new ObservableCollection <UnitVM>();

                _currentFilteredDate      = SelectedDate;
                _currentFilteredWorkShift = SelectedWorkShift;

                _currentFilterTime = VerifyShiftTime();

                List <UnitForceMapModel> unitList = UnitForceMapBusiness.GetUnitForceMapList(SelectedRegion,
                                                                                             SelectedDate, SelectedWorkShift, CurrentFilterTime, (int)SelectedFilterType, out returnMessage);

                foreach (var u in unitList)
                {
                    var unitVM = new UnitVM(u, "Red");
                    UnitList.Add(unitVM);
                }
                SelectedUnit = null;

                FilterUnitCount = unitList.Count.ToString();

                CurrentActiveFilter = SelectedDate.ToString("dd/MM/yyyy") +
                                      " das " + SelectedWorkShift.InicialTime.Hours.ToString().PadLeft(2, '0') + " às " + SelectedWorkShift.FinalTime.Hours.ToString().PadLeft(2, '0') +
                                      " (" + (SelectedFilterType == FilterTypeEnum.ALL ? "Todas AMs" : string.Empty) + (SelectedFilterType == FilterTypeEnum.OUT_SERVICE ? "AMs fora de serviço" : string.Empty) + (SelectedFilterType == FilterTypeEnum.IN_SERVICE ? "AMs em serviço" : string.Empty) +
                                      (string.IsNullOrEmpty(SelectedRegion) ? string.Empty : " da região " + SelectedRegion) + ")";
            }
            catch (Exception ex)
            {
                ShowMessage(ex.Message);
            }
        }
Exemplo n.º 3
0
        public bool Confirm()
        {
            try
            {
                //remove equipe caso tipo de Fora de Serviço seja não operacional, desde que não seja por equipe incompleta
                if (!string.IsNullOrEmpty(SelectedOutType.OutServiceTypeId) &&
                    SelectedOutType.OutServiceTypeId.StartsWith("NO") &&
                    !SelectedOutType.OutServiceTypeId.Equals("NO_EQI") &&
                    !SelectedOutType.OutServiceTypeId.Equals("NO_SEQ"))
                {
                    if (!ShowConfirmMessage("Colocar uma AM como 'Não Operacional' fará ela PERDER SUA EQUIPE. Deseja realmente continuar?"))
                    {
                        return(false);
                    }

                    UnitBusiness.LogOutAllMembers(UnitId);
                    UnitForceMapBusiness.LogOutAllMembers(UnitId);
                    UnitForceMapBusiness.RemoveSubstituteUnit(UnitId);
                }

                int alarmTime = (string.IsNullOrEmpty(AlarmTime) ? 0 : int.Parse(AlarmTime));
                Location = (string.IsNullOrEmpty(Location) ? string.Empty : Location);
                double?mileage = (string.IsNullOrEmpty(Mileage) ? null : (double?)double.Parse(Mileage));

                UnitBusiness.UnitOutOfService(UnitId, SelectedOutType.OutServiceTypeId, Location, alarmTime, mileage, Remarks);

                return(true);
            }
            catch
            {
                ShowMessage("Falha ao realizar solicitação");
            }

            return(false);
        }
Exemplo n.º 4
0
 public void LoadReserveUnitList()
 {
     if (_selectedOutServiceType != null)
     {
         SpecialOutOfServiceType type = (SpecialOutOfServiceType)Enum.Parse(typeof(SpecialOutOfServiceType), _selectedOutServiceType.OutServiceTypeId);
         ReserveUnitList = UnitForceMapBusiness.GetSpecialOutOfServiceUnits(type);
     }
 }
Exemplo n.º 5
0
        public void VerifyShiftChange()
        {
            WorkShiftModel VerifyWorkShift = UnitForceMapBusiness.GetCurrentWorkShift(WorkShiftList);

            if (VerifyWorkShift.ToString() != CurrentWorkShift.ToString())
            {
                CurrentWorkShift = VerifyWorkShift;
            }

            _currentFilterTime = VerifyShiftTime();
        }
Exemplo n.º 6
0
        public void UpdateUnitInForceMap(string unitId)
        {
            UnitVM selectedUnit = this.UnitList.Where(uvm => uvm.UnitModel.UnitId == unitId)
                                  .FirstOrDefault();

            if (selectedUnit != null)
            {
                selectedUnit.UnitModel = UnitForceMapBusiness.GetCurrentUnitForceMap(unitId);
                UnitForceMapBusiness.UpdateUnitForceMap(selectedUnit.UnitModel);
            }
        }
Exemplo n.º 7
0
 private void UpdateUnitType()
 {
     if (!IsURAM)
     {
         SelectedUnit.Category = UnitForceMapBusiness.GetUnitTypeForCrew(SelectedUnit);
     }
     else if (SelectedUnit.Driver == null)
     {
         SelectedUnit.Category = string.Empty;
     }
 }
Exemplo n.º 8
0
        public bool Confirm()
        {
            //try
            //{
            Result = false;

            VerifyRepeatedSelections();

            if (SelectedUnit.Station == null)
            {
                ShowMessage("Selecione a base da viatura");
            }
            else
            {
                if (HasConflicts())
                {
                    ShowMessage("Resolva os conflitos indicados na tela");
                }
                else
                {
                    switch (_currentShiftTime)
                    {
                    case WorkShiftModel.ShiftTime.Actual:

                        SelectedUnit.WorkShiftStarted = "T";

                        Result = UnitForceMapBusiness.UpdateUnitForceMap(SelectedUnit);
                        break;

                    case WorkShiftModel.ShiftTime.Forward:
                        Result = UnitForceMapBusiness.UpdateFutureUnitForceMap(SelectedUnit);
                        break;
                    }

                    if (!Result)
                    {
                        ShowMessage("Falha ao confirmar edição da viatura");
                    }
                }
            }

            /*}
             * catch (UnauthorizedAccessException ex)
             * {
             *  ShowMessage(ex.Message);
             * }
             * catch
             * {
             *  ShowMessage("Falha ao confirmar edição da viatura");
             * }*/

            return(Result);
        }
Exemplo n.º 9
0
        private void LoginSelectedUnit()
        {
            if (!CadBusiness.UnitInService(SelectedTargetUnitId, RemarkText))
            {
                throw new Exception();
            }

            UnitForceMapModel unit = UnitForceMapBusiness.GetCurrentUnitForceMap(SelectedTargetUnitId);

            if (UnitForceMapBusiness.UpdateUnitForceMap(unit) == null)
            {
                throw new Exception();
            }
        }
Exemplo n.º 10
0
 public void CompleteWithPeriodicWorkSchedule(List <WorkScheduleForUnitModel> workScheduleList, ref bool hasError)
 {
     hasError = false;
     try
     {
         List <DateTime> UramDayOffDates = UnitForceMapBusiness.GetDayOffList(StartDate.Value, EndDate.Value, "URAM");
         this.WorkScheduleImported.CompleteWithPeriodicWorkSchedule
             (workScheduleList, StartDate.Value, EndDate.Value, UramDayOffDates, this.IsMergingWorkSchedule);
     }
     catch (Exception ex)
     {
         hasError = true;
         MessageBox.Show(String.Format("Ocorreu um erro ao gerar as escalas periódicas: {0}", ex.Message));
     }
 }
Exemplo n.º 11
0
        public void LoadData()
        {
            string returnMessage;

            SelectedFilterType = FilterTypeEnum.ALL;

            AlertMessage = UnitForceMapBusiness.GetAlertMessage();

            UnitList         = new ObservableCollection <UnitVM>();
            WorkShiftList    = UnitForceMapBusiness.GetWorkShiftList(out returnMessage);
            CurrentWorkShift = UnitForceMapBusiness.GetCurrentWorkShift(WorkShiftList);

            CleanFilter();
            GetUnitList();
            SetRegionList();
        }
Exemplo n.º 12
0
        public bool ValidateUpdatingWorkSchedule()
        {
            bool isValid = true;

            foreach (WorkScheduleForUnitModel ws in WorkScheduleImported.WorkScheduleForUnitList)
            {
                if (!UnitForceMapBusiness.ExistsUnitForceMap(ws.UnitId, ws.ShiftDate.Value, ws.WorkshiftLabel))
                {
                    MessageBox.Show(String.Format("Não existe escala em {0:dd/MM/yyy} {1} para a AM {2}",
                                                  ws.ShiftDate.Value, ws.WorkshiftLabel, ws.UnitId));
                    isValid = false;
                    break;
                }
            }

            return(isValid);
        }
Exemplo n.º 13
0
        public void ImportWorkSchedule_DoWork(object sender, DoWorkEventArgs e)
        {
            List <UnitForceMapModel> unitForceMapList = new List <UnitForceMapModel>();

            if (IsLoading)
            {
                return;
            }

            try
            {
                EnableLoadingProgress("Importando escala");

                unitForceMapList.AddRange(WorkScheduleImported.WorkScheduleForUnitList.Select(ws => ws.ToUnitForceMapModel(_workShiftList)));

                if (unitForceMapList.Where(uf => uf == null).Count() > 0)
                {
                    throw new Exception("Conversão para o mapa força de viatura falhou");
                }

                foreach (UnitForceMapModel uf in unitForceMapList)
                {
                    UnitForceMapBusiness.UpdateFutureUnitForceMap(uf, isCrewUpdating: IsUpdatingWorkSchedule);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(String.Format("Erro na Importação: {0}", exception.Message));
                //ShowMessage(String.Format("Erro na Importação: {0}", exception.Message));
                return;
            }
            finally
            {
                DisableLoadingProgress();
            }

            MessageBox.Show("Importação finalizada com sucesso.");

            CleanFields();

            //ShowMessage("Importação finalizada com sucesso.");
        }
Exemplo n.º 14
0
        public void SaveWorkScheduleTemplate_DoWork(object sender, DoWorkEventArgs e)
        {
            if (IsLoading)
            {
                return;
            }

            try{
                string file = (string)e.Argument;
                EnableLoadingProgress("Gerando arquivo modelo");
                UnitForceMapBusiness.SaveWorkScheduleTemplate(file);
                MessageBox.Show("Arquivo gerado com sucesso");
            }
            catch (Exception exception)
            {
                MessageBox.Show(
                    String.Format("Erro durante a geração do arquivo (obs: é necessário que o Excel esteja instalado): {0}",
                                  exception.Message));
            }
            finally
            {
                DisableLoadingProgress();
            }
        }
Exemplo n.º 15
0
        public void StartQAP()
        {
            if (this.SelectedUnit.UnitModel.OutType != OutOfServiceTypeModel.OUT_TYPE_AGUARDANDO_QAP)
            {
                MessageBox.Show("Apenas viaturas \"Fora de Serviço - Aguardando QAP\" podem ser selecionadas", "Atenção!", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                if (MessageBox.Show("Confirma o início de QAP da AM '" + this.SelectedUnit.UnitModel.UnitId + "'?\n\n (Essa ação não pode ser revertida)", "Atenção!", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    try
                    {
                        UnitForceMapBusiness.StartQAP(this.SelectedUnit.UnitModel);
                        UnitForceMapBusiness.UpdateUnitForceMap(this.SelectedUnit.UnitModel);

                        //SelectedUnit.UnitModel = UnitForceMapBusiness.GetUnitForceMapModel(this.SelectedUnit.UnitModel.UnitId, DateTime.Now, this.CurrentWorkShift);
                    }
                    catch (Exception exception)
                    {
                        throw exception;
                    }
                }
            }
        }
Exemplo n.º 16
0
 private void LoadOutServiceTypeList(string agencyId)
 {
     OutServiceTypeList = UnitForceMapBusiness.GetSpecialOutOfServiceList(agencyId, CurrentUnitForceMap.UnitId);
 }
Exemplo n.º 17
0
        public Style GetDataGridColorStyle()
        {
            Style       gridStyle       = new Style();
            DataTrigger gridDataTrigger = null;

            gridStyle.TargetType = typeof(DataGridRow);

            List <KeyValuePair <string, string> > RegionColorList = UnitForceMapBusiness.GetRegionColorList();

            foreach (KeyValuePair <string, string> Item in RegionColorList)
            {
                gridDataTrigger = new DataTrigger()
                {
                    Binding = new Binding("UnitModel.Station.DispatchGroup"),
                    Value   = Item.Key
                };

                gridDataTrigger.Setters.Add(new Setter()
                {
                    Property = Control.BackgroundProperty,
                    Value    = (SolidColorBrush)(new BrushConverter().ConvertFrom(Item.Value))
                });

                gridStyle.Triggers.Add(gridDataTrigger);
            }

            gridDataTrigger = new DataTrigger()
            {
                Binding = new Binding("UnitModel.StatusId"),
                Value   = "12"
            };

            gridDataTrigger.Setters.Add(new Setter()
            {
                Property = Control.BackgroundProperty,
                Value    = (SolidColorBrush)(new SolidColorBrush(Colors.LightGray))
            });

            gridStyle.Triggers.Add(gridDataTrigger);

            gridDataTrigger = new DataTrigger()
            {
                Binding = new Binding("UnitModel.StatusId"),
                Value   = "14"
            };

            gridDataTrigger.Setters.Add(new Setter()
            {
                Property = Control.BackgroundProperty,
                Value    = (SolidColorBrush)(new SolidColorBrush(Colors.Thistle))
            });

            gridStyle.Triggers.Add(gridDataTrigger);

            gridDataTrigger = new DataTrigger()
            {
                Binding = new Binding("UnitModel.WorkShiftStarted"),
                Value   = "F"
            };

            gridDataTrigger.Setters.Add(new Setter()
            {
                Property = Control.FontWeightProperty,
                Value    = FontWeights.Bold
            });

            gridDataTrigger.Setters.Add(new Setter()
            {
                Property = Control.ToolTipProperty,
                Value    = "Viatura aguardando liberação para atualização."
            });

            gridStyle.Triggers.Add(gridDataTrigger);

            return(gridStyle);
        }
Exemplo n.º 18
0
        /*public Dictionary<WorkScheduleValidationType, WorkScheduleValidationTypeMessage> ValidationsByType {
         *  get { return _validationsByType; }
         *  set
         *  {
         *      _validationsByType = value;
         *      OnPropertyChanged("ValidationsByType");
         *  }
         * }*/

        #endregion

        #region Métodos

        public void LoadValidation_DoWork(object sender, DoWorkEventArgs e)
        {
            if (IsLoading)
            {
                return;
            }

            try
            {
                EnableLoadingProgress("Validando escala");
                string agencyId = "SAMU";
                WorkScheduleImported = new WorkScheduleImportTemplateModel();
                RevortValidationList = new ObservableCollection <ReportValidationItemModel>();

                if (this.IsPeriodicWorkSchedule)
                {
                    if (!ValidatePeriodicWorkScheduleFilter())
                    {
                        DisableLoadingProgress();
                        return;
                    }
                }

                //WorkScheduleImported.WorkScheduleForUnitList

                List <WorkScheduleForUnitModel> workScheduleList = UnitForceMapBusiness.ExtractWorkSchedule(this.FullPathFile).ToList <WorkScheduleForUnitModel>();

                if (this.IsPeriodicWorkSchedule)
                {
                    bool hasError = false;

                    if (workScheduleList.Where(ws => String.IsNullOrEmpty(ws.DateFrequence)).Count() > 0)
                    {
                        DisableLoadingProgress();
                        MessageBox.Show("A frequência de datas deve ser informada em todas as escalas da planilha.\nFavor verificar a planilha de importação.");
                        return;
                    }

                    CompleteWithPeriodicWorkSchedule(workScheduleList, ref hasError);

                    if (hasError || (IsUpdatingWorkSchedule && !ValidateUpdatingWorkSchedule()))
                    {
                        DisableLoadingProgress();
                        return;
                    }
                }
                else
                {
                    WorkScheduleImported.WorkScheduleForUnitList = workScheduleList;
                }

                ReportValidation = new ReportValidationModel();
                ReportValidationBusiness.UpdateReportValidation(WorkScheduleImported, _workShiftList, agencyId, ReportValidation);



                if (IsUpdatingWorkSchedule)
                {
                    this.ReportValidation.ReportValidationItemList.RemoveAll(
                        r => r.WorkScheduleValidationType == WorkScheduleValidationType.CONFLICT_WITH_PREVIOUS_DATA ||
                        r.WorkScheduleValidationType == WorkScheduleValidationType.DATA_SHOULD_BE_FILLED ||
                        r.WorkScheduleValidationType == WorkScheduleValidationType.INVALID_CREW_FORMATION);
                }



                EnableImporting = !ReportValidationBusiness.AreThereErrorMessages(this.ReportValidation);
            }
            catch (SheetNotFoundException exception)
            {
                WorkScheduleImported.WorkScheduleForUnitList = new List <WorkScheduleForUnitModel>();
                ReportValidation = new ReportValidationModel();
                EnableImporting  = false;

                ReportValidation.AddReportItem(WorkScheduleValidationType.SHEET_NAME_NOT_FOUND, WorkScheduleImportTemplateModel.WORK_SCHEDULE_MAIN_SHEET_NAME.ToUpper());
            }
            catch (Exception exception)
            {
                WorkScheduleImported.WorkScheduleForUnitList = new List <WorkScheduleForUnitModel>();
                ReportValidation = new ReportValidationModel();
                EnableImporting  = false;

                MessageBox.Show(String.Format("Erro durante a validação do arquivo: {0}", exception.Message));
                //ShowMessage(String.Format("Erro durante a validação do arquivo: {0}", exception.Message));

                return;
            }
            finally
            {
                DisableLoadingProgress();
            }
        }
Exemplo n.º 19
0
        public bool LoginOutServiceUnit()
        {
            try
            {
                if (string.IsNullOrEmpty(SelectedTargetUnitId))
                {
                    MessageBox.Show("Favor selecionar a AM que entrará em serviço.", "Atenção!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
                else
                {
                    //VERIFICAR SE A UNIDADE POSSUI CNES, NÃO É POSSÍVEL LOGAR UMA VIATURA QUE NÃO POSSUA CNES CADASTRADO.
                    string currentUnitCnes = UnitForceMapBusiness.GetUnitCnes(SelectedTargetUnitId);

                    if (string.IsNullOrEmpty(currentUnitCnes))
                    {
                        MessageBox.Show("Não foi possível logar a AM pois nao existe um CNES cadastrado para a mesma.", "Atenção!", MessageBoxButton.OK, MessageBoxImage.Exclamation);

                        return(false);
                    }

                    string substituteUnitId = UnitForceMapBusiness.GetSubstituteUnitId(SelectedTargetUnitId);
                    if (!string.IsNullOrEmpty(substituteUnitId))
                    {
                        //A UNIDADE SELECTIONADA POSSUI CNES, PORÉM ESTÁ SENDO SUBSTITUÍDA NO MOMENTO POR UMA OUTRA VIATURA,
                        //PRECISA VERIFICAR SE ESSA OUTRA VIATURA TAMBÉM POSSUI CNES ANTES DE PERGUNTAR SOBRE A RETIRADA DO VÍNCULO.
                        string substituteUnitCnes = UnitForceMapBusiness.GetUnitCnes(substituteUnitId);

                        if (string.IsNullOrEmpty(substituteUnitCnes))
                        {
                            MessageBox.Show(string.Format("A unidade {0} está atuando como reserva da selecionada, {1}." +
                                                          Environment.NewLine + "Não é possível colocar a viatura {1} em operação, pois sua reserva {0} não possui um CNES cadastrado." +
                                                          Environment.NewLine + "Substitua a viatura reserva pela oficial caso deseje o retorno da viatura {1} de volta em operação.",
                                                          substituteUnitId, SelectedTargetUnitId), "Viatura possui unidade reserva em operação", MessageBoxButton.OK);

                            return(false);
                        }


                        if (UnitBusiness.IsAssigned(substituteUnitId))
                        {
                            MessageBox.Show(string.Format("A unidade {0}, que está substituindo a selecionada, está EMPENHADA." +
                                                          Environment.NewLine + "Não é possível colocá-la em serviço.",
                                                          substituteUnitId), "Viatura possui reserva empenhada", MessageBoxButton.OK);

                            return(false);
                        }



                        MessageBoxResult msgBoxResult = MessageBox.Show(string.Format("A unidade {0} está atuando como reserva da selecionada, {1}." +
                                                                                      Environment.NewLine + "Deseja remover o vínculo entre elas e manter as duas em operação?",
                                                                                      substituteUnitId, SelectedTargetUnitId), "Viatura possui unidade reserva em operação",
                                                                        MessageBoxButton.OKCancel);
                        if (msgBoxResult == MessageBoxResult.OK)
                        {//string _outServiceTypeId
                            UnitForceMapModel     unitForceTarget  = UnitForceMapBusiness.GetCurrentUnitForceMap(SelectedTargetUnitId);
                            UnitForceMapModel     unitForceCurrent = UnitForceMapBusiness.GetCurrentUnitForceMap(substituteUnitId);
                            OutOfServiceTypeModel outOfServiceType = UnitForceMapBusiness.GetOutOfServiceType(OutOfServiceTypeModel.OUT_TYPE_RESERVA_TECNICA_ID, "SAMU");
                            UnitForceMapBusiness.ExchangeUnit(unitForceCurrent, unitForceTarget, outOfServiceType);


                            //UnitForceMapBusiness.RemoveSubstituteUnit(SelectedTargetUnitId);
                            //LoginSelectedUnit();
                            return(true);
                        }
                    }
                    else
                    {
                        LoginSelectedUnit();
                        return(true);
                    }
                }
            }
            catch (Exception)
            {
                ShowErrorMessage();
            }

            return(false);
        }
Exemplo n.º 20
0
 private void LoadOutServiceTypeList()
 {
     OutServiceTypeList = UnitForceMapBusiness.GetSpecialOutOfServiceList("SAMU", null);
 }