Exemplo n.º 1
0
        private ViewReport ReadForm()
        {
            var model = new ReportValidationModel()
            {
                task        = ComboBox_Tasks.SelectedItem as ViewTask,
                activity    = ComboBox_Activity.SelectedItem as ActivityType?,
                start       = DateTimePicker_BeginTime.Value,
                end         = DateTimePicker_EndTime.Value,
                description = new TextRange(RichTextBox_Description.Document.ContentStart,
                                            RichTextBox_Description.Document.ContentEnd).Text
            };

            if (!_validator.IsModelValid(model))
            {
                Label_Error_list.Content = _validator.ValidationResults;
                return(null);
            }

            _report.taskId      = model.task.Id;
            _report.activity    = (ActivityType)model.activity;
            _report.start       = (DateTime)model.start;
            _report.end         = (DateTime)model.end;
            _report.description = model.description;

            if (_operation != ReportOperation.Delete)
            {
                _report.status = ReportStatus.Open;
            }

            _report.engineerId = Context.CurrentUser.Id;
            _report.effort     = CalculateEffort(_report.start, _report.end);

            return(_report);
        }
Exemplo n.º 2
0
        private static List <string> GetReportedWorkScheduleIds(ReportValidationModel reportValidationModel, ValidationLevelType validationType)
        {
            List <string> rowsWithErrors = reportValidationModel.GetWorkScheduleIds(
                ReportValidationBusiness.WorkScheduleValidationTypeMessageList.Where(
                    ws => ws.Level == validationType).Select(ws => ws.ValidationType).ToList <WorkScheduleValidationType>());

            return(rowsWithErrors);
        }
Exemplo n.º 3
0
        private static void UpdateWorkScheduleWithErrors(ReportValidationModel reportValidationModel, WorkScheduleImportTemplateModel workScheduleTemplate)
        {
            List <string> idsWithWarnings = GetReportedWorkScheduleIds(reportValidationModel, ValidationLevelType.WARNING);
            List <string> idsWithErrors   = GetReportedWorkScheduleIds(reportValidationModel, ValidationLevelType.ERROR);

            workScheduleTemplate.WorkScheduleForUnitList.ForEach(ws => ws.HasWarning = idsWithWarnings.Contains(ws.ID));
            workScheduleTemplate.WorkScheduleForUnitList.ForEach(ws => ws.HasError   = idsWithErrors.Contains(ws.ID));
        }
Exemplo n.º 4
0
 private void CleanFields()
 {
     ReportValidation     = new ReportValidationModel();
     RevortValidationList = new ObservableCollection <ReportValidationItemModel>();
     WorkScheduleImported.WorkScheduleForUnitList = new List <WorkScheduleForUnitModel>();
     WorkScheduleImported = new WorkScheduleImportTemplateModel();
     EnableImporting      = false;
     FullPathFile         = String.Empty;
     CleanWorkSchedulePeriodicFields();
 }
Exemplo n.º 5
0
        public ImportWorkScheduleVM(List <WorkShiftModel> availableWorkshiftList)
        {
            _reportValidation           = new ReportValidationModel();
            _workScheduleImported       = new WorkScheduleImportTemplateModel();
            _workShiftList              = availableWorkshiftList;
            _enableImporting            = false;
            _loadingText                = String.Empty;
            _isLoading                  = false;
            _workShiftPeriodBuilderList = new List <WorkShiftPeriodBuilder>();

            ReportValidationBusiness.LoadValidationsByType();

            IsCreatingWorkSchedule = true;
            IsUpdatingWorkSchedule = false;
            IsMergingWorkSchedule  = false;
        }
Exemplo n.º 6
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.º 7
0
        public static void UpdateReportValidation(WorkScheduleImportTemplateModel workScheduleTemplate, List <WorkShiftModel> availableWorkshiftList, string currentAgencyId, ReportValidationModel repotValidationModel)
        {
            string        returnMessage;
            List <string> validUnitList          = new List <string>();
            List <string> validStationIdList     = new List <string>();
            List <int>    validEmployeeIdNumList = new List <int>();
            List <string> validEmployeeIdList    = new List <string>();

            List <WorkScheduleUnitModel> workScheduleUnitList = new List <WorkScheduleUnitModel>();

            validUnitList          = UnitBusiness.GetActiveUnitsId(currentAgencyId);
            validStationIdList     = CadBusiness.GetCadStationList(currentAgencyId).Select(cs => cs.StationId).ToList <string>();
            validEmployeeIdNumList = GetEmployeeIds(currentAgencyId);

            foreach (int emp in validEmployeeIdNumList)
            {
                validEmployeeIdList.Add(emp.ToString());
            }

            List <DateTime> dateTimeListFromWorkSchedule      = workScheduleTemplate.WorkScheduleForUnitList.Where(ws => ws.ShiftDate.HasValue).Select(ws => ws.ShiftDate.Value).Distinct().ToList <DateTime>();
            List <string>   workshifLabelListfromWorkSchedule = workScheduleTemplate.WorkScheduleForUnitList.Select(ws => ws.WorkshiftLabel).Distinct().ToList <string>();

            workScheduleTemplate.UpdateReportValidationBasedOnNewData(ref repotValidationModel, validStationIdList, validEmployeeIdList, validUnitList, availableWorkshiftList);

            foreach (DateTime date in dateTimeListFromWorkSchedule)
            {
                foreach (WorkShiftModel workShift in availableWorkshiftList.Where(ws => workshifLabelListfromWorkSchedule.Contains(ws.Label)))
                {
                    workScheduleUnitList = WorkScheduleBusiness.GetWorkScheduleList(null, date, workShift, WorkShiftModel.ShiftTime.Forward, (int)FilterTypeEnum.ALL, out returnMessage)
                                           .Where(uf => uf.Driver != null || uf.Doctor != null || uf.Nurse != null || uf.FirstAuxiliar != null || uf.SecondAuxiliar != null || uf.ThirdAuxiliar != null)
                                           .ToList <WorkScheduleUnitModel>();
                    workScheduleTemplate.UpdateReportValidationBasedOnOldData(ref repotValidationModel, availableWorkshiftList, workScheduleUnitList);
                }
            }

            repotValidationModel.JoinIdsOfReportValidationList();

            UpdateWorkScheduleWithErrors(repotValidationModel, workScheduleTemplate);

            if (repotValidationModel.ReportValidationItemList.Count == 0)
            {
                repotValidationModel.AddReportItem(WorkScheduleValidationType.VALIDATED, Properties.Resources.ALERT_MESSAGE_WHEN_NO_ERRORS);
            }
        }
Exemplo n.º 8
0
 public static bool AreThereErrorMessages(ReportValidationModel reportValidationModel)
 {
     return(reportValidationModel.ReportValidationItemList.Where(r => ValidationTypeByMessage[r.WorkScheduleValidationType].Level == ValidationLevelType.ERROR).Count() > 0);
 }
Exemplo n.º 9
0
        public void LoadValidation_DoWork(object sender, DoWorkEventArgs e)
        {
            if (IsLoading)
            {
                return;
            }

            try
            {
                EnableLoadingProgress(Properties.Resources.DIALOG_MESSAGE_VALIDATING_WORK_SCHEDULE);
                WorkScheduleImported = new WorkScheduleImportTemplateModel();
                RevortValidationList = new ObservableCollection <ReportValidationItemModel>();

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

                List <ImportableWorkScheduleUnitModel> workScheduleList = ImportableWorkScheduleBusiness.ExtractWorkSchedule(this.FullPathFile).ToList <ImportableWorkScheduleUnitModel>();

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

                    if (workScheduleList.Where(ws => String.IsNullOrEmpty(ws.DateFrequence)).Count() > 0)
                    {
                        DisableLoadingProgress();
                        MessageBox.Show(Properties.Resources.ALERT_MESSAGE_MISSED_DATE_FREQUENCE);
                        return;
                    }

                    CompleteWithPeriodicWorkSchedule(workScheduleList, ref hasError);

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

                ReportValidation = new ReportValidationModel();
                ReportValidationBusiness.UpdateReportValidation(WorkScheduleImported, _workShiftList, Properties.Settings.Default.AGENCY_ID, 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 <ImportableWorkScheduleUnitModel>();
                ReportValidation = new ReportValidationModel();
                EnableImporting  = false;

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

                MessageBox.Show(String.Format("{0}: {1}", Properties.Resources.ALERT_MESSAGE_ERROR_FILE_VALIDATING, exception.Message));
                return;
            }
            finally
            {
                DisableLoadingProgress();
            }
        }